I am trying to override equals method in Java. I have a class People
which basically has 2 data fields name
and age
. Now I want to ove
Since I'm guessing age
is of type int
:
public boolean equals(Object other){
boolean result;
if((other == null) || (getClass() != other.getClass())){
result = false;
} // end if
else{
People otherPeople = (People)other;
result = name.equals(otherPeople.name) && age == otherPeople.age;
} // end else
return result;
} // end equals