Overriding hashCode() method

Hi,

Question about overriding the hashCode() method. The OCP study guide book states (page 19 just above the real world scenario) that the following situation is not legal:

public int hashCode() { return idNumber * 7 + age; }

The book states: it is not legal because it uses more variables than the equals() method which looked like:

public boolean equals(Lion obj) {

if (obj == null) return false;

return this.idNumber == obj.idNumber;

}

So from what I understand it is not legal to use the age variable in the hashCode() method because it is not used in...

Read More »

By: coderanch.comforumsrssforumTopics24java-programmer-OCPJP - 5 days ago

Related Posts