File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed
src/NandhuDSA/oops/properties/inheritance/MultiLevelinheritance Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments