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

Since x is 2, execution jumps to case 2:. Because there are no break statements, execution falls through to case 3: (printing "3?") and then falls through to case 5: (printing "5?"). Therefore, the output displays both "3" and "5" (with question marks, as written in the print statements).