Multiple choice technology programming languages

class A { void m1(int i) { int j = i % 3; switch (j) { case 0: System.out.print("0"); break; case 1: System.out.print("1"); break; default: assert j == 2; System.out.print(j); }} public static void main (String[] args) { A a = new A(); for (int i=5; i >= -1; i--) {a.m1(i);} }} Which statements are true?

  1. With assertions enabled it prints 210210-1 followed by an AssertionError message.

  2. With assertions enabled it prints 210210 followed by an AssertionError message.

  3. With assertions enabled it prints only 210210

  4. With assertions enabled it prints nothing.

  5. With assertions disabled it prints 210210-1

  6. With assertions disabled it prints only 210210

Reveal answer Fill a bubble to check yourself
B,E Correct answer
Explanation

When i is -1, j = -1 % 3 results in -1. In the switch, -1 goes to default. With assertions enabled, assert j == 2 fails because -1 != 2, throwing an AssertionError after printing "210210". With assertions disabled, it prints "-1".