Multiple choice technology programming languages

public class Test { public static void main(String [] args) { int x =5; boolean b1 = true; boolean b2 = false; if((x==4) && !b2) System.out.print(”l “); System.out.print(”2 “); if ((b2 = true) && b1) System.out.print(”3 “); } } What is the result?

  1. 2

  2. 1 2

  3. 2 3

  4. 1 2 3

  5. Compilation fails.

  6. Exception is thrown at runtime

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

The first condition (x==4) is false since x=5, so '1' is not printed. '2' always prints. The second if assigns b2=true and checks b1=true, so both conditions are true and '3' prints. Output is '2 3'. Note the assignment (b2=true) inside the condition.