nerdexam
Oracle

1Z0-803 · Question #9

Given: What is the result?

The correct answer is B. They really match. 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 method compares values for equality. Compares references, not values. The use of == with object references is generally limited

Working with Selected Classes from the Java API

Question

Given:

What is the result?

Exhibit

1Z0-803 question #9 exhibit

Options

  • AThey match
  • BThey really match
  • CThey match
  • DNothing Prints
  • EThey really match

How the community answered

(49 responses)
  • B
    92% (45)
  • C
    4% (2)
  • D
    2% (1)
  • E
    2% (1)

Explanation

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 method compares values for equality. 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.

Topics

#string comparison#equals method#equality operator#string pool

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice