1Z0-829 Controlling Program Flow Practice Question
Given the following switch statement:
```java
int x = 2;
switch (x) { default: System.out.print("default "); case 1: System.out.print("1 "); case 2: System.out.print("2 "); case 3: System.out.print("3 "); break; case 4: System.out.print("4 ");
}
```
What is the output?
⚠ Common exam trap
The trap here is that candidates often forget fall-through behavior or assume the default case always executes, leading them to pick options that include default or skip the break's effect on subsequent cases.
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
✓
2 3
The switch statement starts execution at the matching case (case 2) and then falls through to subsequent cases until a break statement is encountered. Since case 2 has no break, it prints "2 ", then falls through to case 3, prints "3 ", and the break terminates the switch. The default case is not executed because a matching case was found before it.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
2
Why it's wrong here
Fall-through occurs to case 3.
- ✗
2 3 4
Why it's wrong here
Break in case 3 prevents fall-through to case 4.
- ✓
2 3
Why this is correct
Prints 2, then falls through to 3 and breaks.
- ✗
default 1 2 3
Why it's wrong here
Default only runs if no match; here case 2 matches.
Go deeper
Related to this question
About these practice questions
This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-829 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-829 exam.