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

Discussion

Comparing two objects with == rather than equals - which of the following is true?

  • A.== compares field values for objects and references only for arrays.
  • B.== is rejected by the compiler when both operands are reference types.
  • C.== compares references.
  • D.== calls equals for objects.

Answer: C

For reference types == asks whether the two variables hold the same reference, whatever the class does in equals. That is why two Strings with the same characters can be unequal by == and equal by equals, and why value comparison always goes through equals.

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

Post your comment

Please log in or register to post a comment.