-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInheritance.java
More file actions
137 lines (114 loc) Β· 3.53 KB
/
Inheritance.java
File metadata and controls
137 lines (114 loc) Β· 3.53 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//Inheritance Code
import java.util.*;
import java.io.*;
class Staff {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String name, add;
int code;
public void getData() throws IOException {
System.out.println("Enter the Staff's Code");
code = Integer.parseInt(br.readLine());
System.out.println("Enter the Staff's Name");
name = br.readLine();
System.out.println("Enter the Staff's Address");
add = br.readLine();
}
public void display() {
System.out.println("Code = " + code);
System.out.println("Name = " + name);
System.out.println("Address = " + add);
}
}
class Teacher extends Staff {
String sub, c;
public void getData() throws IOException {
super.getData();
System.out.println("Enter the Teacher's Subject");
sub = br.readLine();
System.out.println("Enter the Teacher's Class");
c = br.readLine();
}
public void display() {
super.display();
System.out.println("Teacher's Subject = " + sub);
System.out.println("Teacher's Class = " + c);
}
}
class Officer extends Staff {
String grade;
public void getData() throws IOException {
super.getData();
System.out.println("Enter the Officer's Grade");
grade = br.readLine();
}
public void display() {
super.display();
System.out.println("Officer's Grade is " + grade);
}
}
class Typist extends Staff {
String speed;
public void getData() throws IOException {
super.getData();
System.out.println("Enter the Typist's Speed");
speed = br.readLine();
}
public void display() {
super.display();
System.out.println("Typist's Speed is " + speed);
}
}
class Regular extends Typist {
String Bp;
public void getData() throws IOException {
super.getData();
System.out.println("Enter the Regular's Basic Pay");
Bp = br.readLine();
}
public void display() {
super.display();
System.out.println("Basic Pay of Regular is " + Bp);
}
}
class AdHoc extends Typist {
String Bp;
public void getData() throws IOException {
super.getData();
System.out.println("Enter the Ad-Hoc's Basic Pay");
Bp = br.readLine();
}
public void display() {
super.display();
System.out.println("Basic pay of Ad-Hoc is " + Bp);
}
}
class Inheritance {
public static void main(String a[]) throws IOException {
System.out.println("\nTeacher's Data");
Teacher s = new Teacher();
s.getData();
System.out.println("\nThe Teacher's Data is:-");
s.display();
System.out.println("\nOfficer's Data");
Officer o = new Officer();
o.getData();
System.out.println("\nThe Officer's Data is:-");
o.display();
System.out.println("\nTypist's Data");
Typist t = new Typist();
t.getData();
System.out.println("\nThe Typist's Data is:-");
t.display();
System.out.println("\nRegular's Data");
Regular r = new Regular();
r.getData();
System.out.println("\nThe Regular's Data is:-");
r.display();
System.out.println("\nAd-Hoc's Data");
AdHoc a1 = new AdHoc();
a1.getData();
System.out.println("\nThe Ad-Hoc's Data is:-");
a1.display();
}
}