1Z0-811 Control Flow and Loops Practice Question
A programmer writes a switch statement to handle different cases. The code compiles and runs, but the output is unexpected: 'A' prints when the input is 'B'. Which is the most likely cause?
⚠ Common exam trap
Oracle often tests the fall-through behavior of switch statements, where candidates mistakenly assume each case automatically exits after its code, overlooking the need for an explicit break statement.
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
✓
A break statement is missing after the case 'B'.
In a switch statement, when a case matches, execution continues sequentially through subsequent cases (fall-through) unless a break statement is encountered. If case 'B' lacks a break, after executing its code, the program falls through to the code for case 'A' (or the next case), printing 'A' even though the input was 'B'. This is the classic fall-through behavior in Java.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
A break statement is missing after the case 'B'.
Why this is correct
Fall-through from case 'B' to case 'A' occurs without break.
- ✗
The switch variable type is char but should be String.
Why it's wrong here
Char is valid for switch; type mismatch would cause compile error, not fall-through.
- ✗
The switch statement is missing a default case.
Why it's wrong here
Missing default does not cause fall-through.
- ✗
The default case is executed instead of the matched case.
Why it's wrong here
Default runs only when no match, but output shows a different matched case.
Go deeper
Related to this question
About these practice questions
One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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-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.