-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathInheritance.java
70 lines (62 loc) · 2.15 KB
/
Inheritance.java
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
66
67
68
69
70
class Doctor {
String Doctor_name;
int Doctor_age;
public Doctor(String name, int age) {
Doctor_name = name;
Doctor_age = age;
}
void doctor_details() {
System.out.printf("Doctor_Details:\n%-10s %-3d\n", Doctor_name, Doctor_age);
}
}
class Surgeon extends Doctor {
String Surgeon_name;
int Surgeon_age;
String Surgeon_Position;
public Surgeon(String name, int age, String position) {
super(name, age);
Surgeon_name = name;
Surgeon_age = age;
Surgeon_Position = position;
}
void surgeon_details() {
System.out.printf("Surgeon_Details:\n%-10s %-3d %-10s\n", Surgeon_name, Surgeon_age, Surgeon_Position);
}
}
class MICU_Surgeon extends Surgeon {
String Micu_surgeon_name;
int Micu_surgeon_age;
String Micu_surgeon_Position;
int Micu_surgeon_Experience;
public MICU_Surgeon(String name, int age, String position, int Experience) {
super(name, age, position);
Micu_surgeon_name = name;
Micu_surgeon_age = age;
Micu_surgeon_Position = position;
Micu_surgeon_Experience = Experience;
}
void micu_surgeon_details() {
System.out.printf("MICU_Surgeon_Details:\n%-10s %-3d %-10s %-3d\n", Micu_surgeon_name, Micu_surgeon_age, Micu_surgeon_Position, Micu_surgeon_Experience);
}
}
public class Inheritance {
public static void main(String[] args) {
Doctor Mann = new Doctor("Mann", 20);
Surgeon Hasti = new Surgeon("Hasti", 19, "Surgeon");
Surgeon Khushali = new Surgeon("Khushali", 19, "Ass.Surgeon");
MICU_Surgeon Manush = new MICU_Surgeon("Manush", 20, "MICU_Surgeon", 10);
Mann.doctor_details();
Hasti.doctor_details();
Hasti.surgeon_details();
Khushali.doctor_details();
Khushali.surgeon_details();
Manush.doctor_details();
Manush.surgeon_details();
Manush.micu_surgeon_details();
Mann.Doctor_name = "Mann Shah";
Mann.doctor_details();
Manush.Doctor_name = "Manush Shah";
Manush.micu_surgeon_details(); // Flaw in the code...
Manush.doctor_details();
}
}