In this program, we will create 2 Interfaces. Each interface contains an abstract method. Then we will implement created interface in a class.
Program/Source Code:
The source code to implement multiple-inheritance using the interface is given below. The given program is compiled and executed successfully.
// Java program to implement multiple-inheritance
// using the interface
interface Inf1 {
void sayHello1();
}
interface Inf2 {
void sayHello2();
}
class Sample implements Inf1, Inf2 {
public void sayHello1() {
System.out.println("Hello World1");
}
public void sayHello2() {
System.out.println("Hello World2");
}
}
public class Main {
public static void main(String[] args) {
Sample S = new Sample();
S.sayHello1();
S.sayHello2();
}
}
Output:
Hello World1
Hello World2
Explanation:
In the above program, we created 2 interfaces Inf1, Inf2. Then we implemented the created interfaces in the Sample class to implement multiple-inheritance.
The Main class contains a method main(). The main() method is the entry point for the program, here we created the object of the Sample class. After that, we called methods and printed the result.
In this program, we will create 2 Interfaces. Each interface contains an abstract method. Then we will implement created interface in a class.
Program/Source Code:
The source code to implement multiple-inheritance using the interface is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created 2 interfaces Inf1, Inf2. Then we implemented the created interfaces in the Sample class to implement multiple-inheritance.
The Main class contains a method main(). The main() method is the entry point for the program, here we created the object of the Sample class. After that, we called methods and printed the result.