Java Program for multilevel inheritance using interface


In this program, You will learn how to implement multilevel inheritance using interface in Java.


interface A { }

class First implements A { }

class Second extends First { }

class Main extends Second { }


Example: How to implement multilevel inheritance using interface in Java

Run it Now
interface A {

    int x = 10;
}

class First implements A {

    int y = 20;
}

class Second extends First {

    int z;

    void add() {
        z = x + y;
    }
}

class Main extends Second {

    void result() {
        System.out.println("The sum is : " + z);
    }

    public static void main(String args[]) {
        Main obj = new Main();
        obj.add();
        obj.result();
    }
}

Output:

The sum is : 30