A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Java program to implement multiple-inheritance using the interface
Q:

Java program to implement multiple-inheritance using the interface

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now