Java Program using inheritance and interface
In this program, You will learn how to implement inheritance and interface in java.
interface First {
//declaration
}
class Second implements First {
//statement
}
class Main extends Second {
//statement
}
Example: How to implement inheritance and interface in java.
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