Java 15
Tue Sep 19 2023 03:54:29 GMT+0000 (Coordinated Universal Time)
Saved by
@viinod07
class Grandparent {
void displayGrandparent() {
System.out.println("This is the Grandparent class.");
}
}
class Parent extends Grandparent {
void displayParent() {
System.out.println("This is the Parent class.");
}
}
class Child extends Parent {
void displayChild() {
System.out.println("This is the Child class.");
}
}
public class MultiLevelInheritanceExample {
public static void main(String[] args) {
Child child = new Child();
child.displayGrandparent(); // Accessing method from Grandparent class
child.displayParent(); // Accessing method from Parent class
child.displayChild(); // Accessing method from Child class
}
}
content_copyCOPY
Comments