here is the q,answers and some explanations:
Given the following definition:
String s = null;
Which code fragment will cause an exception of type NullPointerException to be thrown.
##ans1##
if ((s != null) & (s.length()>0))
##ans2##
if ((s != null) && (s.length()>0))
##ans3##
if ((s != null) | (s.length()>0))
##ans4##
if ((s != null) | | (s.length()>0))
##ans5##
None of the above.
##correct##
1,2,3,4
i checked only 1,3,4 and even I compiled and saw that 2 is not a correct answer,i have doubt about the explanation-for answer 2
"Answer 1 must be fully evaluated. The LHS is true and so the RHS needs to be evaluated to ensure the entire expression is true. This is an AND operation, and if the LHS is true, then the RHS must be evaluated for the expression to be true.
Answer 2 is the same as above. Both sides need to be evaluated for an AND expression to be true (if the LHS is true, that is).."
am i missing something?
rgds,
cristi