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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.