1Z0-829 Controlling Program Flow Practice Question
Given: int x=1; switch(x) { case 1: System.out.print("A"); case 2: System.out.print("B"); break; default: System.out.print("C"); } What is printed?
⚠ Common exam trap
The trap here is that candidates forget that without a break, execution falls through to the next case, so they incorrectly assume only the matching case executes.
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
✓
AB
The switch statement does not have a break after case 1, so execution falls through to case 2 after printing 'A'. Case 2 prints 'B' and then hits the break, exiting the switch. The default case is skipped because a matching case was found. Thus, 'AB' is printed.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
C
Why it's wrong here
Incorrect; default is not reached because break after case 2.
- ✗
ABC
Why it's wrong here
Incorrect; break prevents fall-through to default.
- ✓
AB
Why this is correct
Correct: prints A then B due to fall-through.
- ✗
A
Why it's wrong here
Incorrect; fall-through occurs.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-829 question from scratch — 513 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 →
Same concept, more angles
1 more way this is tested on 1Z0-829
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. What is the output when this code is executed? ```java 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"); } ```
medium- ✓ A.Two Three
- B.Two
- C.Two Three Default
- D.One Two Three
Why A: The switch statement matches the value 2, so it executes the case 'Two' block, which prints 'Two ' and then falls through to the next case because there is no break statement. The case 'Three' block prints 'Three ' and then breaks, exiting the switch. The default case is skipped because a matching case was found and the break in case 'Three' prevents further fall-through. Thus, the output is 'Two Three '.
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.