Preview:
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

    }

}

downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter