The answer is false because s1 and s2 do not reference the same object in memory. When you use the new keyword, as in new String("Java"), Java forces the creation of a brand new String object on the heap, even if an identical string already exists. In contrast, the literal "Java" is placed in the string pool, a special area where Java reuses immutable strings for efficiency. The == operator in Java checks reference equality, not the actual content of the strings, so s1 and s2 point to two different memory locations, yielding false. On the Oracle Java Foundations 1Z0-811 exam, this question tests your understanding of the string pool versus heap allocation, a common trap where students mistakenly think == compares values. The exam often pairs this with a literal-only comparison to highlight the contrast. Memory tip: think of new as forcing a "new address" every time, while literals share a single "home" in the pool.
1Z0-811 Primitives, Strings and Operators Practice Question
This 1Z0-811 practice question tests your understanding of primitives, strings and operators. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
Exhibit
Refer to the exhibit.
public class Test {
public static void main(String[] args) {
String s1 = new String("Java");
String s2 = "Java";
System.out.println(s1 == s2);
}
}
Output: false
Refer to the exhibit.
public class Test {
public static void main(String[] args) {
String s1 = new String("Java");
String s2 = "Java";
System.out.println(s1 == s2);
}
}
Output: false
A
s1 is created with 'new' thus not in string pool, s2 is literal in pool, so different references
Correct: this explains the difference in references.
B
s1 and s2 refer to different objects in the heap
Why wrong: Incomplete: s2 may also be in the pool, not necessarily on heap; the main reason is that new creates a distinct object.
C
The String class does not override equals
Why wrong: Incorrect: String does override equals(), but == is used here.
D
The == operator compares value not reference
Why wrong: Incorrect: == compares references for objects.
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
s1 is created with 'new' thus not in string pool, s2 is literal in pool, so different references
The new keyword forces creation of a new String object in heap. The literal "Java" is interned and may be in the string pool. s1 and s2 refer to different objects, so == returns false.
Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
✓
s1 is created with 'new' thus not in string pool, s2 is literal in pool, so different references
Why this is correct
Correct: this explains the difference in references.
Related concept
Read the scenario before looking for a memorised answer.
✗
s1 and s2 refer to different objects in the heap
Why it's wrong here
Incomplete: s2 may also be in the pool, not necessarily on heap; the main reason is that new creates a distinct object.
✗
The String class does not override equals
Why it's wrong here
Incorrect: String does override equals(), but == is used here.
✗
The == operator compares value not reference
Why it's wrong here
Incorrect: == compares references for objects.
Common exam traps
Common exam trap: answer the scenario, not the keyword
Many certification questions include familiar terms but test a specific constraint. Read the exact wording before choosing an answer that is generally true but wrong for this case.
Detailed technical explanation
How to think about this question
This question should be treated as a scenario, not a definition check. Identify the problem, the constraint and the best action. Then compare each option against those facts.
KKey Concepts to Remember
Read the scenario before looking for a memorised answer.
Find the constraint that changes the correct option.
Eliminate answers that are true in general but not in this case.
Use explanations to understand the rule behind the answer.
TExam Day Tips
→Underline the problem statement mentally.
→Watch for words such as best, first, most likely and least administrative effort.
→Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Real-world example
How this comes up in practice
A practitioner preparing for the 1Z0-811 exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.
What to study next
Got this wrong? Here's your next step.
Identify which 1Z0-811 exam domain this question belongs to, then review the specific concept being tested. Practise related questions in that domain and focus on understanding why each wrong answer is tempting — not just why the correct answer is right.
Primitives, Strings and Operators — This question tests Primitives, Strings and Operators — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: s1 is created with 'new' thus not in string pool, s2 is literal in pool, so different references — The new keyword forces creation of a new String object in heap. The literal "Java" is interned and may be in the string pool. s1 and s2 refer to different objects, so == returns false.
What should I do if I get this 1Z0-811 question wrong?
Identify which 1Z0-811 exam domain this question belongs to, then review the specific concept being tested. Practise related questions in that domain and focus on understanding why each wrong answer is tempting — not just why the correct answer is right.
What is the key concept behind this question?
Read the scenario before looking for a memorised answer.
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 →
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. A developer writes the following code: String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2); What is the output?
easy
A.Compilation fails
B.false
✓ C.true
D.Hello
Why C: Option C is correct because string literals in Java are interned, meaning both s1 and s2 refer to the same String object in the string constant pool. The == operator compares object references, not content, so since both variables point to the same interned string, the comparison yields true.
Variation 2. What is the output of the following code? String s1 = "Hello"; String s2 = "Hello"; System.out.println(s1 == s2);
medium
A.Hello
✓ B.true
C.Compilation error
D.false
Why B: String literals are interned, so both references point to the same object in the string pool, and == compares references, resulting in true.
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.
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.