public class Test
{
public int aMethod()
{
static int i = 0;
i++;
return i;
}
public static void main(String args[])
{
Test test = new Test();
test.aMethod();
int j = test.aMethod();
System.out.println(j);
}
}
A -
0
B -
1
C -
2
D -
Compilation fails.
2-
What will be the output of the program?
class PassA
{
public static void main(String [] args)
{
PassA p = new PassA();
p.start();
}
void start()
{
long [] a1 = {3,4,5};
long [] a2 = fix(a1);
System.out.print(a1[0] + a1[1] + a1[2] + " ");
System.out.println(a2[0] + a2[1] + a2[2]);
}
long [] fix(long [] a3)
{
a3[1] = 7;
return a3;
}
}
A -
12 15
B -
15 15
C -
3 4 5 3 7 5
D -
3 7 5 3 7 5
3-
What will be the output of the program?
class Equals
{
public static void main(String [] args)
{
int x = 100;
double y = 100.1;
boolean b = (x = y); /* Line 7 */
System.out.println(b);
}
}
A -
true
B -
false
C -
Compilation fails
D -
An exception is thrown at runtime
4-
What will be the output of the program?
class Bitwise
{
public static void main(String [] args)
{
int x = 11 & 9;
int y = x ^ 3;
System.out.println( y | 12 );
}
}
int x = l, y = 6;
while (y--)
{
x++;
}
System.out.println("x = " + x +" y = " + y);
A -
x = 6 y = 0
B -
x = 7 y = 0
C -
x = 6 y = -1
D -
Compilation fails.
7-
What will be the output of the program?
for (int i = 0; i < 4; i += 2)
{
System.out.print(i + " ");
}
System.out.println(i); /* Line 5 */
A -
0 2 4
B -
0 2 4 5
C -
0 1 2 3 4
D -
Compilation fails.
8-
What will be the output of the program?
int x = 3;
int y = 1;
if (x = y) /* Line 3 */
{
System.out.println("x =" + x);
}
A -
x = 1
B -
x = 3
C -
Compilation fails.
D -
The code runs with no output.
9-
What will be the output of the program?
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (RuntimeException ex) /* Line 10 */
{
System.out.print("B");
}
catch (Exception ex1)
{
System.out.print("C");
}
finally
{
System.out.print("D");
}
System.out.print("E");
}
public static void badMethod()
{
throw new RuntimeException();
}
}
A -
BD
B -
BCD
C -
BDE
D -
BCDE
10-
public class ExceptionTest
{
class TestException extends Exception {}
public void runTest() throws TestException {}
public void test() /* Point X */
{
runTest();
}
}
At Point X on line 5, which code is necessary to make the code compile?