Multiple choice technology programming languages

public static void main(String[] args) { String str = "null"; if (str == null) { System.out.println("null"); } else (str.length() == 0) { System.out.println("zero"); } else { System.out.println("some"); } } What is the result?

  1. null

  2. zero

  3. some

  4. Compilation fails

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The code has syntax error: else if (str.length() == 0) is missing the if keyword. It should be else if (str.length() == 0) not else (str.length() == 0). This causes compilation failure.