Java Package
© examsiri.com
Question : 1 of 16
Marks:
+1,
-0
Given:
What is the appropriate definition of the hashCode method in class Person?
public class Person {
  private String name, comment;
  private int age;
  public Person(String n, int a, String c) {
   name = n; age = a; comment = c;
  }
  public boolean equals(Object o) {
   if (! (o instanceof Person)) return false;
   Person p = (Person)o;
   return age == p.age && name.equals(p.name);
  }
} What is the appropriate definition of the hashCode method in class Person?
Go to Question: