Q:

Java program to implement multiple-inheritance using the interface

belongs to collection: Java Interface Programs

0

Java program to implement multiple-inheritance using the interface

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 Inf1Inf2. 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.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java program to implement interface with hierarchi... >>
<< Java program to implement the interface with multi...