Java Program using inheritance and interface


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


interface First { }

class Second implements First { }

class Main extends Second { }


Example: How to implement inheritance and interface in Java

Run it Now
interface First {

    void change();
}

class Second implements First {

    int num;

    public void change() {
        num = 10;
    }
}

class Main extends Second {

    void display() {
        System.out.println("The num value is : " + num);
    }

    public static void main(String args[]) {
        Main t = new Main();
        t.change();
        t.display();
    }
}

Output:

The num value is : 10