Multiple choice technology programming languages

What is the output of following piece of code ? int x = 2; switch (x) { case 1:System.out.println(”1?); case 2: case 3:System.out.println(”3?); case 4: case 5:System.out.println(”5?); }

  1. No output

  2. 3 and 5

  3. 1, 3 and 5

  4. 3

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

This switch statement demonstrates fall-through behavior. With x=2, execution jumps to case 2 (which has no statement), then falls through to case 3 and prints 3. Since there's no break, it continues to case 5 and prints 5. The output shows both 3 and 5 printed on separate lines.