public class BoolTest
{
public static void main(String [] args)
{
int result = 0;
Boolean b1 = new Boolean("TRUE");
Boolean b2 = new Boolean("true");
Boolean b3 = new Boolean("tRuE");
Boolean b4 = new Boolean("false");
if (b1 == b2) /* Line 10 */
result = 1;
if (b1.equals(b2) ) /* Line 12 */
result = result + 10;
if (b2 == b4) /* Line 14 */
result = result + 100;
if (b2.equals(b4) ) /* Line 16 */
result = result + 1000;
if (b2.equals(b3) ) /* Line 18 */
result = result + 10000;
System.out.println("result = " + result);
}
}
A -
0
B -
1
C -
10
D -
10010
2-
What will be the output of the program?
public class ObjComp
{
public static void main(String [] args )
{
int result = 0;
ObjComp oc = new ObjComp();
Object o = oc;
if (o == oc)
result = 1;
if (o != oc)
result = result + 10;
if (o.equals(oc) )
result = result + 100;
if (oc.equals(o) )
result = result + 1000;
System.out.println("result = " + result);
}
}
A -
1
B -
10
C -
101
D -
1101
3-
What will be the output of the program?
public class Example
{
public static void main(String [] args)
{
double values[] = {-2.3, -1.0, 0.25, 4};
int cnt = 0;
for (int x=0; x < values.length; x++)
{
if (Math.round(values[x] + .5) == Math.ceil(values[x]))
{
++cnt;
}
}
System.out.println("same results " + cnt + " time(s)");
}
}
A -
same results 0 time(s)
B -
same results 2 time(s)
C -
same results 4 time(s)
D -
Compilation fails.
4-
What will be the output of the program?
public class Test178
{
public static void main(String[] args)
{
String s = "foo";
Object o = (Object)s;
if (s.equals(o))
{
System.out.print("AAA");
}
else
{
System.out.print("BBB");
}
if (o.equals(s))
{
System.out.print("CCC");
}
else
{
System.out.print("DDD");
}
}
}
A -
AAACCC
B -
AAADDD
C -
BBBCCC
D -
BBBDDD
5-
What will be the output of the program?
String x = "xyz";
x.toUpperCase(); /* Line 2 */
String y = x.replace('Y', 'y');
y = y + "abc";
System.out.println(y);
A -
abcXyZ
B -
abcxyz
C -
xyzabc
D -
XyZabc
6-
What will be the output of the program?
int i = (int) Math.random();
A -
i = 0
B -
i = 1
C -
value of i is undetermined
D -
Statement causes a compile error
7-
What will be the output of the program?
class A
{
public A(int x){}
}
class B extends A { }
public class test
{
public static void main (String args [])
{
A a = new B();
System.out.println("complete");
}
}
A -
It compiles and runs printing nothing
B -
Compiles but fails at runtime
C -
Compile Error
D -
Prints "complete"
8-
What will be the output of the program?
int i = 1, j = 10;
do
{
if(i++ > --j) /* Line 4 */
{
continue;
}
} while (i < 5);
System.out.println("i = " + i + "and j = " + j); /* Line 9 */
A -
i = 6 and j = 5
B -
i = 5 and j = 5
C -
i = 6 and j = 6
D -
i = 5 and j = 6
9-
Which three form part of correct array declarations?
public int a [ ]
static int [ ] a
public [ ] int a
private int a [3]
private int [3] a [ ]
public final int [ ] a
A -
1, 2, 6
B -
2, 4, 5
C -
1, 3, 4
D -
2, 5, 6
10-
In the given program, how many lines of output will be produced?
public class Test
{
public static void main(String [] args)
{
int [] [] [] x = new int [3] [] [];
int i, j;
x[0] = new int[4][];
x[1] = new int[2][];
x[2] = new int[5][];
for (i = 0; i < x.length; i++)
{
for (j = 0; j < x[i].length; j++)
{
x[i][j] = new int [i + j + 1];
System.out.println("size = " + x[i][j].length);
}
}
}
}