Java Program for multilevel inheritance using the interface


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


interface A { 
  //declaration
}

class First implements A { 
   //statement
}

class Second extends First { 
     //statement
}

class Main extends Second { 
    //statement
}

Example: How to implement multilevel inheritance using the interface in java

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