1Z0-811 Primitives, Strings and Operators Practice Question
Exhibit
String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2);
Refer to the exhibit. What is the output?
⚠ Common exam trap
Oracle often tests the distinction between `==` (reference equality) and `equals()` (value equality) with strings, and the trap here is that candidates assume `==` always compares content, missing the interning behavior of string literals that makes the reference comparison `true`.
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
✓
true
The code uses `==` to compare two `String` objects created with string literals (e.g., `String s1 = "true"; String s2 = "true";`). In Java, string literals are interned, meaning they refer to the same object in the string pool. Therefore, the reference comparison returns `true`. The `==` operator checks reference equality, not content equality, but due to interning, the references are the same. If `new String("true")` were used, the comparison would be `false` because different objects are created.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Runtime exception
Why it's wrong here
No exception.
- ✓
true
Why this is correct
Correct: same object from string pool.
- ✗
Compilation error
Why it's wrong here
Code compiles fine.
- ✗
false
Why it's wrong here
They are the same reference.
Go deeper
Related to this question
About these practice questions
This 1Z0-811 question is part of Courseiva's 481-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 →
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.