Multiple choice technology programming languages

Which of the following statements are true about the default implementation of the public int hashCode() method of the Object class?

  1. The Object class does not provide any implementation for the hashCode method; every class must override it

  2. As far as it may be practically possible, the hashCode method defined by the Object class does return distinct integers for distinct objects

  3. For two object references referring to the same object, the hashCode method returns the same integer

  4. It returns a fixed number that internally represents the Object class for the JVM

  5. Only choice D is correct

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

According to the Java documentation, the default hashCode() method in the Object class is defined to return distinct integers for distinct objects as far as is reasonably practical (typically by converting the internal memory address of the object). Note that option C is also a true property of any valid hashCode contract, but option B describes the behavior of the default implementation specifically.