14
[30] What will be the output of the code snippet given below?  public class Main {  public static void main ( String[ ] args ) { int i, j, k ; for ( i = 0 ; i <= 3 ; i++ ) { for( j = 0 ; j <= 3 - i ; j++ ) System.out.print ( "*" ) ; for ( k = 0 ; k <= i ; k++ ) System.out.print ( i ) ; } } } Choice a **********0123 Choice b **********0112223333 Choice c ………… ****0***11**222*3333 Choice d 0112223333********** [29] What will be the output of the code snippet given below?  public class Main {  public static void main ( String[ ] args ) { int x = 5, y = 6, z = 7, w = 8, p = x++ * y++ / z++ * ++w, q = x++ * ++y * ++z / p * w++, r = x-- * y-- * --z / --q ; System.out.println ( x + " " + y + " " + z + " " + w + " " + p + " " + q + " " + r ) ; } } Choice a …………. 6 7 8 10 36 107 4 Choice b

j2ee wt ANS

Embed Size (px)

Citation preview

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 1/14

[30] What will be the output of the code snippet given below?

 public class Main{ public static void main ( String[ ] args ){int i, j, k ;for ( i = 0 ; i <= 3 ; i++ ){for( j = 0 ; j <= 3 - i ; j++ )System.out.print ( "*" ) ;for ( k = 0 ; k <= i ; k++ )System.out.print ( i ) ;}}}

Choice a**********0123

Choice b

**********0112223333

Choice c …………

****0***11**222*3333

Choice d

0112223333**********

[29] What will be the output of the code snippet given below?

 public class Main{ public static void main ( String[ ] args ){int x = 5, y = 6, z = 7, w = 8, p = x++ * y++ / z++ * ++w, q = x++ * ++y * ++z / p * w++, r = x--* y-- * --z / --q ;System.out.println ( x + " " + y + " " + z + " " + w + " " + p + " " + q + " " + r ) ;}}

Choice a ………….

6 7 8 10 36 107 4

Choice b

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 2/14

5 6 7 8 36 107 4

Choice c

6 7 8 10 37 108 5

Choice d

5 6 7 8 37 108 5

[28] Which of the following statement is correct about the code snippet given below?

 public class Main{ public static void main ( String[ ] args ){int bar = 1 ;

{int bar = 2 ;System.out.println ( bar ) ;}}}

Choice a ………

The code reports an error. …….

Choice b

The code causes an exception

Choice c

The code gives an output as 1.

Choice d

The code gives an output as 2.

[27] What will be the output of the code snippet given below?

 public class Main{ public static void main ( String[ ] args ){int x ;x = 10 ;if ( x == 10 ){

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 3/14

int y = 20 ;System.out.println ( x + " " + y ) ;x = y * 2 ;}System.out.println ( x ) ;}}

Choice a

10 2010

Choice b ………..

10 2040

Choice c

40 2040

Choice d

20 2010

[26] What will be the output of the code snippet given below?

 public class Main{ public static void main ( String[ ] args ){double pi, r, a ;r = 10.8 ; pi = 3.1416 ;a = pi * r * r ;System.out.println ( a ) ;}}

Choice a …………

366.436224

Choice b

366.44

Choice c

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 4/14

366.43

Choice d

366.430000

[25] Which of the following statement is correct about the code snippet given below?

 public class Main{ public static void main ( String[ ] args ){int i = 400 * 400 / 400 ;if ( i == 400 )System.out.println ( "In if" ) ;elseSystem.out.println ( "In else" ) ;

}}

Choice a

The code reports an error.

Choice b

The code causes an exception

Choice c …………….

The code gives an output as In if.

Choice d

The code gives an output as In else

[24] What will be the output of the code snippet given below?

 public class Main{

 public static void main ( String[ ] args ){double a = 3.0, b = 4.0 ;double c = Math.sqrt ( a * a + b * b ) ;System.out.println ( c ) ;}}

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 5/14

Choice a

5.00

Choice b

5

Choice c ………..

5.0

Choice d

5.000000

[23] What will be the output of the code snippet given below?

 public class Main{ public static void main ( String[ ] args ){int x = 10, y = 20 ; boolean a, b ;a = ! ( x > y ) ; b = x < y ;System.out.print ( a + " " + b ) ;}}

Choice a

0 1

Choice b

false true

Choice c

1 1

Choice d ………….

true true

[22] Which of the following statements are correct? I. The relational operators determine therelationship that one operand has to the other. II. The relational operators determine equality andordering.

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 6/14

Choice a

Only I is correct.

Choice b

Only II is correct.

Choice c …………..

Both I and II are correct.

Choice d

Both I and II are incorrect.

[21] Which of the following statements are correct? I. In Java, the else clause is optional. II. if 

condition is any expression that returns any character value.

Choice a …………….

Only I is correct.

Choice b

Only II is correct.

Choice c

Both I and II are correct.

Choice d

Both I and II are incorrect.

[20] Which of the following statements are correct? I. For each left shift, the high-order bit isshifted out and lost and a zero is brought in on the left. II. When a left shift is applied to an intoperand, bits are lost once they are shifted past bit position 63.

Choice a

Only I is correct.Choice b

Only II is correct.

Choice c

Both I and II are correct.

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 7/14

Choice d ………..

Both I and II are incorrect.

[19] Which of the following selection statements are supported by Java? I. if II. switch III.Macro

Choice a ………..

Only I and II

Choice b

Only I and III

Choice c

Only II and III

Choice d

I, II and III

[18] Which of the following statements are correct? I. Nested if else statements are not allowedin java. II. if statements are executed from top to down.

Choice a

Only I is correct.

Choice b ………..

Only II is correct.

Choice c

Both I and II are correct.

Choice d

Both I and II are incorrect.

[17] Which of the following statements are correct? I. if statement is Java’s conditional branchstatement. II. if statement is used to route program execution through two different paths.

Choice a

Only I is correct.

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 8/14

Choice b

Only II is correct.

Choice c …………

Both I and II are correct.

Choice d

Both I and II are incorrect.

[16] Which of the following statements are correct? I. When the division operator is applied toan integer type, there will be a fractional component attached to the result. II. In Java, modulusoperator cannot be applied to floating-point types.

Choice a

Only I is correct.

Choice b

Only II is correct.

Choice c

Both I and II are correct.

Choice d ………..

Both I and II are incorrect.

[15] Which of the following statements are correct? I. In Java, an integer literal cannot beassigned to a long variable. II. To specify a long literal, user needs to explicitly tell the compiler that the literal value is of type long by appending an upper or lowercase L to the literal.

Choice a

Only I is correct.

Choice b ………….

Only II is correct.

Choice c

Both I and II are correct.

Choice d

Both I and II are incorrect.

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 9/14

[14] Which of the following statements are correct? I. The type float specifies a single-precisionvalue that uses 64 bits of storage. II. Java uses Unicode to represent characters.

Choice a

Only I is correct.

Choice b ………..

Only II is correct.

Choice c

Both I and II are correct.

Choice d

Both I and II are incorrect.

[13] Which of the following statements are correct? I. boolean data type is returned by allrelational operators. II. When a boolean value is output by println( ), 1 or 0 gets displayed.

Choice a ………

Only I is correct.

Choice b

Only II is correct.

Choice c

Both I and II are correct.

Choice d

Both I and II are incorrect.

[12] Which of the following statements are correct? I. Floating-point numbers are used whenevaluating expressions that require fractional precision. II. Java implements the standard set of 

floating-point types and operators.

Choice a

Only I is correct.

Choice b

Only II is correct.

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 10/14

Choice c ………….

Both I and II are correct.

Choice d

Both I and II are incorrect.

[11] Which of the following statements are correct? I. The Java compiler checks all expressionsand parameters to ensure that the types are compatible. II. In Java, we can assign a floating-pointvalue to an integer.

Choice a …………

Only I is correct.

Choice b

Only II is correct.

Choice c

Both I and II are correct.

Choice d

Both I and II are incorrect.

[10] Which of the following statements are correct? I. Java manages the meaning of the high-order bit by adding an unsigned right shift operator. II. The Java run-time environment is free touse whatever size it wants, as long as the types behave as user declared them.

Choice a

Only I is correct.

Choice b

Only II is correct.

Choice c ………..

Both I and II are correct.

Choice d

Both I and II are incorrect.

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 11/14

[9] Which of the following statements are correct? I. In Java, char is 8-bit type. II. We havenegative chars in Java.

Choice a

Only I is correct.

Choice b

Only II is correct.

Choice c

Both I and II are correct.

Choice d ……..

Both I and II are incorrect.

[8] Which of the following statements are correct? I. The simple data types are defined to havean explicit range and mathematical behavior. II. In Java all data types have a strictly definedrange.

Choice a

Only I is correct.

Choice b

Only II is correct.

Choice c ………..

Both I and II are correct.

Choice d

Both I and II are incorrect.

[7] Which of the following statements are correct? I. In Java, a byte is a signed 8-bit type entity.II. The smallest integer data type is short.

Choice a ………..

Only I is correct.

Choice b

Only II is correct.

Choice c

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 12/14

Both I and II are correct.

Choice d

Both I and II are incorrect.

[6] Which of the following statements are correct? I. We can operate on chars as if they areintegers. II. Java has a simple data type boolean for logical values.

Choice a

Only I is correct.

Choice b

Only II is correct.

Choice c ………..

Both I and II are correct.

Choice d

Both I and II are incorrect.

[5] Which of the following statements are correct? I. In Java octal values are denoted by aleading zero. II. In Java, the value 09 produces an error.

Choice a

Only I is correct.

Choice b

Only II is correct

Choice c ………..

Both I and II are correct.

Choice d

Both I and II are incorrect.

[4] Which of the following statements are correct? I. The long data type is the most versatile andefficient type. II. Data type determines behavior and not size.

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 13/14

Choice a

Only I is correct.

Choice b …………..

Only II is correct.

Choice c

Both I and II are correct.

Choice d

Both I and II are incorrect.

[3] Which of the following statements are correct? I. In Java an int is always 32 bits regardless of 

the particular platform. II. Java supports unsigned, positive-only integers.

Choice a ……………

Only I is correct.

Choice b

Only II is correct.

Choice c

Both I and II are correct.

Choice d

Both I and II are incorrect.

[2] Which of the following statements are correct? I. In Java, variables of type int are commonlyemployed to control loops and to index arrays. II. Any time we have an integer expressioninvolving bytes, shorts, ints and literal numbers, the entire expression is promoted to int beforethe calculation is done.

Choice a

Only I is correct.

Choice b

Only II is correct.

Choice c …………

Both I and II are correct.

8/3/2019 j2ee wt ANS

http://slidepdf.com/reader/full/j2ee-wt-ans 14/14

Choice d

Both I and II are incorrect.

[1] Which of the following statements are correct? I. Integer literals create an int value. II. InJava, when a literal value is assigned to a byte or short variable, an error is generated even if theliteral value is within the range of the target type.

Choice a ……

Only I is correct.

Choice b

Only II is correct.

Choice c

Both I and II are correct.

Choice d

Both I and II are incorrect.