Multiple choice technology programming languages

What will be the result of compiling and running the following code? (Assume that assertions are enabled at compile time as well as at runtime.) class Test { String f(int i) { switch (i) { case 0: return "A"; case 1: return "B"; case 2: return "C"; default: assert false; } } public static void main(String[] args) { Test t = new Test(); for (int i = 0; i < 4; i++) { System.out.print(t.f(i)); } } }

  1. Prints "ABC" and throws AssertionError

  2. Prints "ABC" and throws AssertionException

  3. Prints "ABC" and exits without any error

  4. Compilation error

  5. Run time exception

  6. None of the above

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

The code has a compilation error because the default case uses assert false without a proper expression. In Java, assert requires a boolean expression or a boolean expression with a string message. The syntax assert false: is incomplete.