Multiple choice

Which two statements are true about properly overridden hashCode() and equals() methods?

  1. hashCode() doesn't have to be overridden if equals() is.
  2. equals() doesn't have to be overridden if hashCode() is.
  3. hashCode() can always return the same value, regardless of the object that invoked it.
  4. equals() can be true even if it's comparing different objects.

  1. 1 and 2

  2. 2 and 3

  3. 3 and 4

  4. 1 and 3

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Statements (3) and (4) are correct. Statements (1) and (2) are incorrect because hashCode() and equals() can't be overridden.