1Z0-811 Control Flow and Loops Practice Question
Which THREE of the following are valid types that can be used as a switch expression in Java (as of Java 8)?
⚠ Common exam trap
The 1Z0-811 exam often tests the misconception that `long` is a valid switch type because it is a numeric primitive, but the JVM's switch bytecode only supports 32-bit integer types, making `long` invalid.
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
✓
String
In Java 8, a switch expression can use `String`, `char`, and `int` as valid types. `String` was added in Java 7, and `char` and `int` are among the original primitive types supported. `long` and `boolean` are not allowed because `long` is a 64-bit type not supported by the switch statement's underlying `tableswitch` or `lookupswitch` bytecode instructions, and `boolean` has only two values, making it unsuitable for switch's multi-branch logic.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
long
Why it's wrong here
long is not allowed; only int and smaller integer types.
- ✓
String
Why this is correct
String is valid since Java 7.
- ✓
char
Why this is correct
char is a valid switch type.
- ✓
int
Why this is correct
int is a valid switch type.
- ✗
boolean
Why it's wrong here
boolean is not allowed in switch.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-811 question from scratch — 481 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-811 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-811 exam.