Which of the following class level (nonlocal) variable declarations will not compile?
A -
protected int a;
B -
transient int b = 3;
C -
private synchronized int e;
D -
volatile int d;
2-
What will be the output of the program?
public class ArrayTest
{
public static void main(String[ ] args)
{
float f1[ ], f2[ ];
f1 = new float[10];
f2 = f1;
System.out.println("f2[0] = " + f2[0]);
}
}
A -
It prints f2[0] = 0.0
B -
It prints f2[0] = NaN
C -
An error at f2 = f1; causes compile to fail.
D -
It prints the garbage value.
3-
class A
{
A( ) { }
}
class B extends A
{ }
Which statement is true?
A -
Class B'S constructor is public.
B -
Class B'S constructor has no arguments.
C -
Class B'S constructor includes a call to this( ).
D -
None of these.
4-
/* Missing statements ? */
public class NewTreeSet extends java.util.TreeSet
{
public static void main(String [] args)
{
java.util.TreeSet t = new java.util.TreeSet();
t.clear();
}
public void clear()
{
TreeMap m = new TreeMap();
m.clear();
}
}
which two statements, added independently at beginning of the program, allow the code to compile?
No statement is required
import java.util.*;
import.java.util.Tree*;
import java.util.TreeSet;
import java.util.TreeMap;
A -
1 only
B -
2 and 5
C -
3 and 4
D -
3 and 4
5-
What will be the output of the program?
class Two
{
byte x;
}
class PassO
{
public static void main(String [] args)
{
PassO p = new PassO();
p.start();
}
void start()
{
Two t = new Two();
System.out.print(t.x + " ");
Two t2 = fix(t);
System.out.println(t.x + " " + t2.x);
}
Two fix(Two tt)
{
tt.x = 42;
return tt;
}
}
A -
null null 42
B -
0 0 42
C -
0 42 42
D -
0 0 0
6-
What will be the output of the program?
public class If2
{
static boolean b1, b2;
public static void main(String [] args)
{
int x = 0;
if ( !b1 ) /* Line 7 */
{
if ( !b2 ) /* Line 9 */
{
b1 = true;
x++;
if ( 5 > 6 )
{
x++;
}
if ( !b1 )
x = x + 10;
else if ( b2 = true ) /* Line 19 */
x = x + 100;
else if ( b1 | b2 ) /* Line 21 */
x = x + 1000;
}
}
System.out.println(x);
}
}
A -
0
B -
1
C -
101
D -
107
7-
What will be the output of the program?
public class If1
{
static boolean b;
public static void main(String [] args)
{
short hand = 42;
if ( hand < 50 & !b ) /* Line 7 */
hand++;
if ( hand > 50 ); /* Line 9 */
else if ( hand > 40 )
{
hand += 7;
hand++;
}
else
--hand;
System.out.println(hand);
}
}
A -
41
B -
42
C -
51
D -
52
8-
What will be the output of the program?
int i = O;
while(1)
{
if(i == 4)
{
break;
}
++i;
}
System.out.println("i = " + i);
A -
i = 0
B -
i = 3
C -
i = 4
D -
Compilation fails.
9-
What will be the output of the program?
int i = 0, j = 5;
tp: for (;;)
{
i++;
for (;;)
{
if(i > --j)
{
break tp;
}
}
System.out.println("i =" + i + ", j = " + j);
A -
i = 1, j = 0
B -
i = 1, j = 4
C -
i = 3, j = 4
D -
Compilation fails.
10-
What will be the output of the program?
int I = 0;
label:
if (I < 2) {
System.out.print("I is " + I);
I++;
continue label;
}