1Z0-829 Controlling Program Flow Practice Question
Which TWO correctly describe the behavior of the following code?
```java
int x = 10;
switch (x) { case 10: System.out.print("ten "); default: System.out.print("default "); case 20: System.out.print("twenty ");
}
```
⚠ Common exam trap
The trap here is that candidates mistakenly believe the default case is optional or must be last, or that a matching case prevents fall-through, when in fact Java executes all subsequent cases (including default) until a break or the end of the switch block.
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
✓
The output is 'ten default twenty '.
In a Java switch statement, once a matching case is found, all subsequent cases (including the default case) are executed in order until a break statement is encountered. Here, case 10 matches, so it prints 'ten ', then falls through to default (prints 'default '), then falls through to case 20 (prints 'twenty '), producing 'ten default twenty '. This is known as fall-through behavior.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The default case is never executed because a matching case exists.
Why it's wrong here
Default executes due to fall-through from case 10.
- ✗
The output is 'ten default ' because case 20 is skipped.
Why it's wrong here
Case 20 is not skipped; it prints after default.
- ✗
The code does not compile because default must be the last case.
Why it's wrong here
Default can appear anywhere, though unusual.
- ✓
The output is 'ten default twenty '.
Why this is correct
Correct sequence: ten, default, twenty.
- ✓
The code compiles and runs, producing output due to fall-through.
Why this is correct
No break statements cause fall-through.
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.