Can you answer my Java questions?
After finding lot of Java users here, I thought of starting this thread where questions on Java (from simple ones to higher ones ) will be asked, not by me 😉. Anyone can ask and anyone can answer.Questions asked will be on random basis, no specific topics will be taken.OK
Only rule is explanation of the answer should be given clearly. Not just answer is enough. No off the topic discussions should be made here.
So here goes a question from my side
public class Person{Thanks for following rules also.
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.?
Options
a) return super.hashcode();
b) return name.hashcode() + age*7;
c) return name.hashcode() + comment.hashcode()/2;
d) return name.hashcode() + comment.hashcode()/2 -age*3;