Courseiva
Control Flow and LoopsmediumMultiple ChoiceObjective-mapped

1Z0-811 Control Flow and Loops Practice Question

Exhibit

Refer to the exhibit.

public class SwitchTest {
    public static void main(String[] args) {
        int x = 2;
        switch(x) {
            case 1:
                System.out.print("One ");
            case 2:
                System.out.print("Two ");
            case 3:
                System.out.print("Three ");
                break;
            default:
                System.out.print("Default");
        }
    }
}

What is the output of the program?

⚠ Common exam trap

Oracle often tests the concept of fall-through in switch statements, where candidates mistakenly assume that each case is isolated and requires a break to avoid compilation errors, or that the default case always executes regardless of a match.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Two Three

The switch statement matches the value 2, executing the case 2 block which prints 'Two'. Since there is no break statement, execution falls through to case 3, printing 'Three'. The default case is not executed because fall-through stops at the end of the switch block. Thus, the output is 'Two Three'.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Two

    Why it's wrong here

    Fall-through causes case 3 to execute.

  • Two Three Default

    Why it's wrong here

    Break after case 3 prevents default execution.

  • Compilation fails because case 2 is missing a break.

    Why it's wrong here

    Missing break is allowed, leads to fall-through.

  • Two Three

    Why this is correct

    Fall-through from case 2 to case 3, then break.

About these practice questions

Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.