Does the following class satisfy the Java Hash Code contract? Explain. public class Politician{ String firstName; String lastName; /I...assume other fields and constructors are implemented public...


java


Does the following class satisfy the Java Hash Code contract? Explain.<br>public class Politician{<br>String firstName;<br>String lastName;<br>/I...assume other fields and constructors are implemented<br>public boolean equals(Object obj) {<br>if (obj<br>this)<br>==<br>return true;<br>if (!(obj instanceof Politician)<br>return false;<br>Politician pol = (Politician)obj;<br>boolean returnVal = (this.firstName+this.lastName).equals(pol.firstName+pol.lastName));<br>return returnVal;<br>}<br>public int hashCode() {<br>return lastName.hashCode(); //last name is a String, so lastName.hashCode() is defined<br>the String implementation<br>}<br>

Extracted text: Does the following class satisfy the Java Hash Code contract? Explain. public class Politician{ String firstName; String lastName; /I...assume other fields and constructors are implemented public boolean equals(Object obj) { if (obj this) == return true; if (!(obj instanceof Politician) return false; Politician pol = (Politician)obj; boolean returnVal = (this.firstName+this.lastName).equals(pol.firstName+pol.lastName)); return returnVal; } public int hashCode() { return lastName.hashCode(); //last name is a String, so lastName.hashCode() is defined the String implementation }

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here