1Z0-829 Controlling Program Flow Practice Question
Given the following switch expression with colon syntax, what is the result when code equals 2? int val = switch(code) { case 1: yield 10; case 2: yield 20; default: yield 30; };
⚠ Common exam trap
Many candidates think colon syntax requires break instead of yield, or that yield is only for arrow syntax, but Java allows yield in both colon and arrow forms for switch expressions.
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
✓
20
When code equals 2, the switch expression matches case 2: and executes the yield 20; statement, which returns 20 as the value assigned to val. The colon syntax with yield is valid in Java 14+ switch expressions, and each case must yield a value.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
20
Why this is correct
20 is the yield for case 2.
- ✗
10
Why it's wrong here
10 is the yield for case 1.
- ✗
30
Why it's wrong here
30 is the default yield.
- ✗
Compilation error
Why it's wrong here
The switch expression is valid and compiles.
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 →
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.