Skip to content

Commit 57827fd

Browse files
committed
Multi level inheritance and simple override
1 parent 9c5d13e commit 57827fd

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package NandhuDSA.oops.properties.inheritance.MultiLevelinheritance;
2+
3+
public class Animals {
4+
void eat(){
5+
System.out.println("this animal can eat");
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package NandhuDSA.oops.properties.inheritance.MultiLevelinheritance;
2+
3+
// dog extends or inherit animals class then puppy access dog class so puppy access dog properties and animals properties this is multi level inheritance
4+
public class Dog extends Animals{
5+
String bark = "barking";
6+
void Bark(){
7+
System.out.println("Dog is" + " " + bark);
8+
}
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package NandhuDSA.oops.properties.inheritance.MultiLevelinheritance;
2+
3+
public class MultiInheritance {
4+
public static void main(String[] args) {
5+
// dog inherit animals class , then puppy inherit dog class so puppy access all class properties
6+
// now creating puppy class object then access all proprieties
7+
8+
Puppy puppy = new Puppy();
9+
puppy.Bark();
10+
11+
// now creating dog object this object not access puppy properties
12+
Dog beagle = new Dog();
13+
beagle.eat();
14+
}
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package NandhuDSA.oops.properties.inheritance.MultiLevelinheritance;
2+
3+
public class Puppy extends Dog{
4+
void weap(){
5+
System.out.println("i can weap");
6+
}
7+
// override dog bark function
8+
void Bark(){
9+
System.out.println("Puppy is weaping");
10+
}
11+
}

0 commit comments

Comments
 (0)