1Z0-811 String.equals() Practice Question
Exhibit
Refer to the exhibit.
public class DataTypes {
public static void main(String[] args) {
boolean flag = true;
if (flag = false) {
System.out.println("False");
} else {
System.out.println("True");
}
}
}What is the output?
```java
public class Test {
public static void main(String[] args) {String s1 = "hello"; String s2 = "hello"; System.out.println(s1.equals(s2));
} }
```
⚠ Common exam trap
Candidates often confuse == with equals(). In this code, using == would also return true due to string interning, but the question uses equals() to compare content. The trap is that some may think equals() compares references or that the output would be 'False' if they misremember the behavior.
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 compares two String objects 's1' and 's2' using the equals() method. Since both strings have the same content "hello", equals() returns true. The System.out.println statement then prints 'True'.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
No output
Why it's wrong here
No output: Incorrect because the code compiles and runs, producing output.
- ✓
True
Why this is correct
True: Correct because String.equals() compares content, and both strings have the same content 'hello'.
- ✗
Compilation error
Why it's wrong here
Compilation error: Incorrect; the code compiles and runs without error.
- ✗
False
Why it's wrong here
False: Incorrect because equals() returns true for equal strings.
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.