forked from jainaman224/Algo_Ds_Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hierarchical.java
96 lines (75 loc) · 1.71 KB
/
Hierarchical.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
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
class Person
{
private String name;
private long phno;
public void read()
{
name = "Akash";
phno = 928374993;
}
public void show()
{
System.out.println("Name = " + name);
System.out.println("Phone = " + phno);
}
}
class Student extends Person
{
private int rollno;
private String course;
public void read()
{
super.read();
rollno = 007;
course = "Computer Science";
}
public void show()
{
super.show();
System.out.println("Roll No. = " + rollno);
System.out.println("Course = " + course);
}
}
class Teacher extends Person
{
private String dept_name;
private String qual;
public void read()
{
super.read();
dept_name = "CSE";
qual = "PhD";
}
public void show()
{
super.show();
System.out.println("Departement = " + dept_name);
System.out.println("Qualififcation = " + qual);
}
}
class Hierarchical
{
public static void main(String args[])
{
Student s1 = new Student();
s1.read();
System.out.println("******************** Displaying Student Information ********************");
s1.show();
Teacher t1 = new Teacher();
t1.read();
System.out.println("******************** Displaying Teacher Information ********************");
t1.show();
}
}
/* OUTPUT
******************** Displaying Student Information ********************
Name = Akash
Phone = 928374993
Roll No. = 7
Course = Computer Science
******************** Displaying Teacher Information ********************
Name = Akash
Phone = 928374993
Departement = CSE
Qualififcation = PhD
*/