1Z0-829 Controlling Program Flow Practice Question
Which statement is correct about the following switch expression? String result = switch(day) { case MONDAY, TUESDAY -> "weekday"; case WEDNESDAY -> "midweek"; default -> "other"; };
⚠ Common exam trap
Test-takers frequently confuse switch statements (which do not require a semicolon) with switch expressions (which do require a semicolon), leading them to overlook the mandatory semicolon at the end of the expression.
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 switch expression must be terminated with a semicolon.
Switch expressions in Java must be terminated with a semicolon, as they produce a value that is assigned to a variable. The given code uses the arrow syntax (->) and assigns the result to a String variable, so a semicolon is required at the end of the entire switch expression.
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 switch expression is not allowed with a colon.
Why it's wrong here
Switch expressions can use either colon or arrow syntax; colon syntax is allowed.
- ✓
The switch expression must be terminated with a semicolon.
Why this is correct
A switch expression is a statement that must end with a semicolon.
- ✗
The default branch is optional.
Why it's wrong here
The switch expression must be exhaustive; since not all enum constants are covered, a default branch is required.
- ✗
The arrow operator requires a yield statement.
Why it's wrong here
In arrow syntax, the value is provided directly after the arrow; yield is not used.
Go deeper
Related to this question
About these practice questions
One of 513 original 1Z0-829 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-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.