Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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) {
}
}