Courseiva
Controlling Program FloweasyMultiple SelectObjective-mapped

1Z0-829 Controlling Program Flow Practice Question

Which TWO of the following are valid forms of the switch statement/expression in Java?

⚠ Common exam trap

A common mix-up: candidates confuse the syntax of switch statements and switch expressions, mistakenly applying arrow syntax or yield to a switch statement, or thinking break can carry a value like in some other languages.

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

switch(x) { case 1: System.out.println("one"); break; }

It uses the traditional switch statement syntax with a colon after the case label, a statement to execute, and a break statement to prevent fall-through. This is a valid and long-standing form of the switch statement 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.

  • switch(x) { case 1 -> "one"; }

    Why it's wrong here

    Missing semicolon or yield; arrow form requires expression or block.

  • switch(x) { case 1: System.out.println("one"); break; }

    Why this is correct

    Valid traditional switch statement.

  • String r = switch(x) { case 1 -> "one"; default -> "other"; };

    Why this is correct

    Valid switch expression with arrow.

  • String r = switch(x) { case 1: break "one"; };

    Why it's wrong here

    break cannot return a value; use yield in arrow form.

  • switch(x) { case 1: yield "one"; }

    Why it's wrong here

    Colon form does not support yield; yield is for arrow form only.

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.