Courseiva
Question 57 of 513
Controlling Program FlowhardMultiple ChoiceObjective-mapped

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.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 25, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.