-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearInheritanceTest.java
More file actions
81 lines (61 loc) · 1.82 KB
/
Copy pathLinearInheritanceTest.java
File metadata and controls
81 lines (61 loc) · 1.82 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
public class LinearInheritanceTest {
public static void main(String[] args) {
StaffMember sm = new StaffMember(101, "Vedangi", 100000);
sm.printStaffMember();
System.out.println("--------------");
Teacher t = new Teacher(201, "Joe", 30000, "Computer Networks", 100);
t.printTeacher();
System.out.println("---------------");
HOD1 hod = new HOD1(301, "Jonas", 50000, "DBMS", 100, "MongoDB");
hod.printHOD1();
System.out.println("----------------");
}
}
class StaffMember
{
int staffId;
String staffName;
float salary;
public StaffMember(int staffId, String staffName, float salary) {
super();
this.staffId = staffId;
this.staffName = staffName;
this.salary = salary;
}
void printStaffMember()
{
System.out.println("Staff Id: "+staffId);
System.out.println("Staff Name: "+staffName);
System.out.println("Salary: "+salary);
}
}
class Teacher extends StaffMember
{
String subjectTeacher;
int noOfStudents;
public Teacher(int staffId, String staffName, float salary, String subjectTeacher, int noOfStudents) {
super(staffId, staffName, salary);
this.subjectTeacher = subjectTeacher;
this.noOfStudents = noOfStudents;
}
void printTeacher()
{
super.printStaffMember();
System.out.println("Subject Name: "+subjectTeacher);
System.out.println("No of Students teacher is teaching: "+noOfStudents);
}
}
class HOD1 extends Teacher
{
String newSubject;
public HOD1(int staffId, String staffName, float salary, String subjectTeacher, int noOfStudents,
String newSubject) {
super(staffId, staffName, salary, subjectTeacher, noOfStudents);
this.newSubject = newSubject;
}
void printHOD1()
{
super.printTeacher();
System.out.println("HOD added new Subject to curriculum: "+newSubject);
}
}