Java every object has an equals and a hashcode method that


Program: In Java, every object has an equals and a hashCode method that is used, among other things, by the standard Collections library. By default both are based on an object's memory location, but best practice dictates that they should be overridden to be dependant on the object's state. The rule that should be followed when doing this is: if two objects are equal, then they should have the same hash code value.

Which of the following situations would be permissible and which would not under this rule?

Provide a brief justification.
(a) Two objects have the same hash code and are equal
(b) Two objects are equal but have di?erent hash codes
(c) Two objects have the same hash code but are not equal
(d) Two objects have di?erent hash codes and are not equal

I'm not sure how to answer the question and implement the hashCode method

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Java every object has an equals and a hashcode method that
Reference No:- TGS0949146

Expected delivery within 24 Hours