Multiple choice technology programming languages

  1. 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. 2

  2. 3

  3. 1 2

  4. 2 3

  5. 1 2 3

  6. Compilation fails.

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

The first condition (x==4) && !b2 is false because x=5, so '1' is not printed. Print('2') always executes, printing '2'. The second condition (b2 = true) assigns true to b2, then evaluates (true && b1) which is true, so '3' is printed. Output: '2 3'.