Multiple choice technology programming languages

What will be printed out if you attempt to compile and run the following code ? int i=1; switch (i) { case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2: System.out.println("two"); default: System.out.println("default"); }

  1. one

  2. one, default

  3. one, two, default

  4. default

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

When i=1, case 1 matches and prints "one". Since there's no break statement, execution "falls through" to case 2 (prints "two") and then to default (prints "default"). Fall-through is a deliberate (and sometimes useful) feature in Java switch statements.