Exam 1z0-808 Topic 12 Question 63 Discussion

Actual exam question for Oracle's 1z0-808 exam
Question #: 63
Topic #: 12
Given the code fragment:
String h1 = "Bob";
String h2 = new String ("Bob");
What is the best way to test that the values of h1 and h2 are the same?

Suggested Answer: B Vote an answer

The equals method compares values for equality.
Incorrect answers:
The strings are not the same objects so the == comparison fails.
See note #1 below.
As the value of the strings are the same equals is true.
The equals compares values for equality.
There is no generic comparison method named same.
= = (with a space) is not a valid method.
Note: #1 ==
Compares references, not values.
The use of == with object references is generally limited to the following:
Comparing to see if a reference is null.
Comparing two enum values. This works because there is only one object for each enum constant.
You want to know if two references are to the same object.

by Kirk at Apr 08, 2026, 07:42 AM

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Nick name: Submit Cancel
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

0
0
0
10