Multiple choice technology programming languages

What is the output for the below code ? public class Test { public static void main(String... args) { for(int i = 2; i < 4; i++) for(int j = 2; j < 4; j++) assert i!=j : i; } }

  1. The class compiles and runs, but does not print anything.

  2. The number 2 gets printed with AssertionError

  3. The number 3 gets printed with AssertionError

  4. compile error

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

When assertions are enabled, the loop executes. When i = 2 and j = 2, the assert condition i != j fails. The detail message is the value of i (2). Thus, an AssertionError is thrown printing 2. If assertions are disabled, it prints nothing, but the standard test behavior assumes -ea is enabled.