Skip to content

Commit 69ac2e4

Browse files
Updated Inheritance
1 parent 4224d52 commit 69ac2e4

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Object Oriented Programming/L3 - Inheritance/Inheritance.MD

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,34 @@ Here Dog ```IS-A``` relationship with Animal.
6060
* Multiple Inheritance.
6161
* Hierarchial Inheritance.
6262

63+
**On the basis of classification Java supports only 3 inheritances Single, Multi-level, Hybrid and the other two Multiple and Hierarchial is been supported by interface only.**
64+
6365
## Single Inheritance
6466

67+
When a class inherits another class is called Single Inheritance.
68+
69+
```
70+
class Animal{
71+
public void eat(){
72+
System.out.println("Eating");
73+
}
74+
}
75+
76+
class Dog extends Animal{
77+
public void bark(){
78+
System.out.println("Barking");
79+
}
80+
}
81+
82+
class Test{
83+
public static void main(String[] args){
84+
Dog d = new Dog();
85+
d.eat();
86+
d.bark();
87+
}
88+
}
89+
```
90+
91+
```Output:``` <br>
92+
Eating <br>
93+
Barking
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Animal{
2+
public void eat(){
3+
System.out.println("Eating");
4+
}
5+
}
6+
7+
class Dog extends Animal{
8+
public void bark(){
9+
System.out.println("Barking");
10+
}
11+
}
12+
13+
class Test{
14+
public static void main(String[] args){
15+
Dog d = new Dog();
16+
d.eat();
17+
d.bark();
18+
}
19+
}

0 commit comments

Comments
 (0)