Courseiva
Controlling Program FloweasyMultiple ChoiceObjective-mapped

1Z0-829 Controlling Program Flow Practice Question

Which of the following correctly uses a switch expression with multiple constants per case?

```java

int day = 2;

String result = switch (day) { case 1, 2, 3 -> "Weekday"; case 6, 7 -> "Weekend"; default -> "Invalid";

};

```

What is the value of result?

⚠ Common exam trap

Oracle often tests whether candidates know that multiple constants per case are allowed in modern Java (since Java 14), and the trap here is that some candidates mistakenly believe this syntax is invalid or that the default branch would be selected for a value that matches an explicit case.

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

Weekday

The switch expression correctly uses multiple constants per case with the arrow syntax. Since day is 2, it matches case 1, 2, 3, so the expression evaluates to "Weekday". The switch expression is exhaustive (covers all possible int values via the default branch), so it compiles and runs without error.

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 code does not compile because multiple constants are not allowed.

    Why it's wrong here

    Multiple constants per case are allowed in Java 14+.

  • Weekday

    Why this is correct

    Correct match.

  • Invalid

    Why it's wrong here

    Default only runs if no match.

  • Weekend

    Why it's wrong here

    Weekend is for days 6 and 7.

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 →

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.