These are questions from Jxam.
1.Given the following defenition
which code fragment will cause a NullPointerException to be thrown?
(e)None of the above
The answer given is a,b,c,d.But I think choice b is wrong.The reason is,as LHS is false so the RHS does not needs to be
evaluated because of &&.This makes the entire expression to be false.
Correct me if i'm wrong.
2.Given the following ,what would be the correct answers?
static String s="abcd";
public static void method()
(a)code fails to compile,because cannot make a static reference to non-static variables.
(b)compiles fine,if x is declared to be static.
(c)compiles fine by removing the keyword static from the declaration of method()
The answers are a,b,c.
I do not agree with c.The reason is eventhough by removing the keyword static from the method(),in the expression
System.out.println(s+x) s is a String declared as static.so code fails to compile,coz cannot make non- static reference to static
Am I correct?If not correct me.