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

In this switch statement, x=2 matches case 2 which has no break statement, causing fall-through to case 3 which prints "3" followed by another fall-through to case 5 which prints "5". The output is therefore "3" and "5" printed on separate lines.