Multiple choice technology programming languages

Question 3 Given: 11. public class Test { 12. public static void main(String [] args) { 13. int x =5; 14. boolean b1 = true; 15. boolean b2 = false; 16. 17.if((x==4) && !b2) 18. System.out.print(”l “); 19. System.out.print(”2 “); 20. if ((b2 = true) && b1) 21. System.out.print(”3 “); 22. } 23. } What is the result?

  1. D. 2 3

  2. A. 2 B. 3

  3. C. 1 2 E. 1 2 3

  4. F. Compilation fails. G. Au exceptional is thrown at runtime.

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

Tracing the code: x=5, so x==4 is false, and the first if short-circuits without printing 1. Then 2 is printed. b2 = true assigns true, and b1 is true, so the second if condition is true, printing 3. Output is 2 3. Option A (D. 2 3) matches this.