String s = null;
if (s != null && s.length() > 0) {
System.out.println("non-empty");
} else {
System.out.println("empty or null");
}What is printed?
- Acheck_circle
empty or null
- B
non-empty
- C
NullPointerException
- D
Nothing
Explanation
Short-circuit evaluation: s != null is false, so s.length() is never evaluated and no NPE occurs; the else branch runs.