🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Control Flow: all 10 questions

Quiz: Java Control Flow · Question 3 of 10

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        int n = 2;
        switch (n) {
            case 1: System.out.print("one ");
            case 2: System.out.print("two ");
            case 3: System.out.print("three ");
        }
    }
}
  1. A.two
  2. B.two three
  3. C.one two three
  4. D.three
Answer & explanation

Correct answer: two three

Without break, execution falls through from case 2 into case 3.

Can you get the rest right without peeking?

Take the timed Quiz: Java Control Flow quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →