Multiple choice technology web technology

What is the output for the below code ? public class Test { public static void main(String[] args) { Boolean expr = true; if (expr) { System.out.println("true"); } else { System.out.println("false"); } } }

  1. false

  2. Compile Error - can't use Boolean object in if().

  3. true

  4. Compile Properly but Runtime Exception.

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

Java allows Boolean objects in if() statements due to autounboxing. The Boolean object 'expr' with value true autounboxes to primitive true, so the condition is satisfied and 'true' is printed. This is valid Java syntax - no compilation or runtime error occurs.