forked from fineanmol/Hacktoberfest2024
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMultilevelInheri.txt
120 lines (62 loc) · 1.3 KB
/
MultilevelInheri.txt
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
What is Multilevel Inheritance In Java?
In Java (and in other object-oriented languages) a class can get features from another class. This mechanism is known as inheritance.
When multiple classes are involved and their parent-child relation is formed in a chained way then such formation is known as multi-level inheritance.
In multilevel inheritance, a parent a class has a maximum of one direct child class only.
In multi-level inheritance, the inheritance linkage is formed in a linear way and minimum 3 classes are involved.
Code re-usability can be extended with multi-level inheritance.
class Person
{
Person()
{
System.out.println("Person constructor");
}
void nationality()
{
System.out.println("Indian");
}
void place()
{
System.out.println("Mumbai");
}
}
class Emp extends Person
{
Emp()
{
System.out.println("Emp constructor");
}
void organization()
{
System.out.println("IBM");
}
void place()
{
System.out.println("New York");
}
}
class Manager extends Emp
{
Manager()
{
System.out.println("Manager constructor");
}
void subordinates()
{
System.out.println(12);
}
void place()
{
System.out.println("London");
}
}
class Check
{
public static void main(String arg[])
{
Manager m=new Manager();
m.nationality();
m.organization();
m.subordinates();
m.place();
}
}