Tricky SCJP Q
I have bumped on to a website which provide previous SCJP questions for reference. I want to share it here so people can know how tricky it was. Have fun!
public class SCJPTest
{
private static int j = 0;
private static boolean methodB(int k)
{
j = k;
return true;
}
public static void methodA(int i)
{
boolean b;
b = i < 10 | methodB(4);
b = i < 10 || methodB(8);
}
public static void main(String[] args)
{
methodA(0);
System.out.println(j);
}
}
Compile and run this program to get the answer for it. Below are some choices of answer :
What is the result?
A. The program prints “0″
B. The program prints “4″
C. The program prints “8″
D. The program prints “12″
E. The code does not complete.
Filed under: Educational, Fun, Infotainment, Java, Open Source, Sun Microsystem, Technology





