Skip to content
Snippets Groups Projects
EqualsMain.java 1017 B
Newer Older
Joel Cavat's avatar
Joel Cavat committed
class Person {
  protected int id;
  protected String name;
  public Person(int id, String name) {
    this.id = id; this.name = name;
  }
  @Override public String toString() {
    return "Person(" + this.id + ", " + this.name + ")";
  }
  @Override public boolean equals(Object o) {
    if(this == o) return true;
    if(o == null || !(o instanceof Person)) {
      return false; }
    Person p = (Person)o;
    return p.id == this.id && p.name.equals(this.name);
  } 
}

class Patient extends Person {
    public Patient(int id, String name) {
      super(id, name);
    }
    @Override public String toString() {
      return "Patient(" + this.id + ", " + this.name + ")";
    }
    @Override public boolean equals(Object o) {
      if(this == o) return true;
      if(o == null || !(o instanceof Patient)) {
        return false; }
      Patient p = (Patient)o;
      return p.id == this.id && p.name.equals(this.name);
    } 
  }

public class EqualsMain {
    public static void main(String[] args) {


    }
}