Level 3 programs
This commit is contained in:
26
MultiLevelInheritance.java
Normal file
26
MultiLevelInheritance.java
Normal file
@@ -0,0 +1,26 @@
|
||||
//Write a program in java to demonstrate multilevel inheritance in java.
|
||||
|
||||
public class MultiLevelInheritance {
|
||||
void eat() {
|
||||
System.out.println("eating...");
|
||||
}
|
||||
}
|
||||
class Dog extends MultiLevelInheritance {
|
||||
void bark() {
|
||||
System.out.println("barking...");
|
||||
}
|
||||
}
|
||||
class BabyDog extends Dog {
|
||||
void weep() {
|
||||
System.out.println("weeping...");
|
||||
}
|
||||
}
|
||||
|
||||
class TestInheritance {
|
||||
public static void main(String args[]) {
|
||||
BabyDog d=new BabyDog();
|
||||
d.weep();
|
||||
d.bark();
|
||||
d.eat();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user