The program is run with java -ea Example43 - what will be the output?
public class Example43
{
public static void main(String[] args)
{
String s = null;
assert s != null && s.length() > 0;
System.out.println("ok");
}
}
Answer: C
The conditional-and operator short-circuits: s != null is false, so s.length() is never evaluated and there is no NullPointerException. The whole expression is false, so the assertion throws an AssertionError. Written with & instead of && it would be a NullPointerException.
Please log in or register to report this question.