Question 508 of 481
1Z0-811 Java Basics and Syntax Practice Question
A developer uses a switch statement with a String variable. Which is true about this usage?
⚠ Common exam trap
Oracle often tests the Java version where String support was introduced (Java 7), and the trap here is that candidates who learned Java before 7 or who confuse switch with older limitations may incorrectly think Strings are not allowed or that only primitives work.
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
✓
It works with strings starting from Java 7
Starting from Java 7 (JSR 334), the switch statement supports String objects in addition to primitive types and enums. The compiler uses the `hashCode()` and `equals()` methods of the String class to evaluate the switch expression against case labels, making it a valid and efficient way to branch on string values.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
It works only with primitive types
Why it's wrong here
Strings are allowed since Java 7, not only primitives.
- ✗
It causes a compilation error because strings are not supported
Why it's wrong here
Strings are supported in switch from Java 7 onward.
- ✓
It works with strings starting from Java 7
Why this is correct
Switch on strings is valid since Java 7.
- ✗
It requires a default case
Why it's wrong here
Default case is optional.
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 →
Last reviewed: Jun 30, 2026
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.
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.
Sign in to join the discussion.