Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which one of the following statements about what Object's own equals method compares is true?

  • A.Object.equals returns true only when both references point at the same object.
  • B.Object.equals compares the fields of the two objects one by one.
  • C.Object.equals compares the values returned by the two objects' toString methods.
  • D.Object.equals compares the two objects' hash codes and nothing else.

Answer: A

The inherited implementation is the most discriminating equivalence possible: it returns true if and only if x == y, that is when the two references are the same object. A class that wants value equality has to override it, which is why two distinct objects holding identical data are unequal by default.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.