Multiple choice technology programming languages

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. 0

  5. 2

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

With x equal to 2, the switch matches case 2. Because there are no break statements, execution falls through case 2 to case 3 (printing '3'), and then falls through case 4 to case 5 (printing '5').