-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverridding.java
More file actions
65 lines (49 loc) · 1.27 KB
/
overridding.java
File metadata and controls
65 lines (49 loc) · 1.27 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class overridding {
public static void main(String[] args) {
Doctor[] doctors = new Doctor[] {
new Doctor("Dr. Patel"),
new Dentist("Dr. Mehta"),
new Cardiologist("Dr. Roy"),
new Surgeon("Dr. Singh")
};
for (Doctor d : doctors) {
d.consultationFee();
}
}
}
class Doctor {
String name;
Doctor(String name) {
this.name = name;
}
void consultationFee() {
System.out.println(name + " (General Doctor) consultation fee: Rs. 500");
}
}
class Dentist extends Doctor {
Dentist(String name) {
super(name);
}
@Override
void consultationFee() {
System.out.println(name + " (Dentist) consultation fee: Rs. 800");
}
}
class Cardiologist extends Doctor {
Cardiologist(String name) {
super(name);
}
@Override
void consultationFee() {
System.out.println(name + " (Cardiologist) consultation fee: Rs. 1200");
}
}
class Surgeon extends Doctor {
Surgeon(String name) {
super(name);
}
@Override
void consultationFee() {
System.out.println(name + " (Surgeon) consultation fee: Rs. 2000");
}
}