Here is the main class.
public class Person {
private String name;
public Person() {
name = "";
}
Its equal method is this
public boolean equals(Object otherObject) {
boolean isEqual = false;
if(otherObject != null && otherObject instanceof Person) {
Person otherPerson = (Person) otherObject;
if(this.name.equals(otherPerson.name))
isEqual = true;
}
return isEqual;
}
I have a subclass that extends the Person class.
public class Student extends Person {
private int studentNumber;
public Student() {
super();
studentNumber = 0;
}
How would I go about writing its equal method that will compare two object of type Student and will compare both variables. Name and studentNumber. So far i have it similar to the Person class.
public boolean equals(Object otherObject) {
boolean isEqual = false;
if(otherObject != null && otherObject instanceof Student) {
Student otherPerson = (Student) otherObject;
if(this.studentnumber.equals(otherPerson.studentnumber))
isEqual = true;
}
return isEqual;
}