1Z0-829 Controlling Program Flow Practice Question
Exhibit
Refer to the exhibit.
```
Error: incompatible types: bad type in switch expression
return switch(day) {
^
required: int
found: String
```What is the likely cause of this compilation error? ```java String day = "Monday";
int dayNum = switch (day) {case 1 -> 1; case 2 -> 2; default -> 0;
};
System.out.println(dayNum); ```
⚠ Common exam trap
The trap here is that candidates often overlook the type compatibility requirement and focus on syntax details like arrow syntax or missing default, assuming the error is about completeness or assignment rather than a fundamental type mismatch.
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 selector is a String but case labels are int constants.
In a Java switch expression, the selector type and case label types must be compatible. If the selector is a String, the case labels must be String constants; int constants would cause a compilation error due to type mismatch. Options A, B, and C describe syntax issues that are not the primary cause here.
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 uses arrow syntax but the keys are not unique.
Why it's wrong here
Duplicate case labels would be a different error.
- ✗
The switch expression is missing a default case.
Why it's wrong here
Missing default gives a different error about not all values covered.
- ✗
The switch expression is not assigned to a variable.
Why it's wrong here
Switch expression must be assigned or used; but missing assignment gives a different error.
- ✓
The switch selector is a String but case labels are int constants.
Why this is correct
Switch expression requires consistent types; likely String selector with int cases.
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.