English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Java Basic Tutorial

Java flow control

Java array

Java object-oriented (I)

Java object-oriented (II)

Java object-oriented (III)

Java Exception Handling

Java List

Java Queue (queue)

Java Map collection

Java Set collection

Java input/output (I/O)

Java Reader/Writer

Other Java topics

Java program implements multiple inheritance

Comprehensive Java Examples

In this example, we will learn how to implement multiple inheritance in Java.

To understand this example, you should understand the followingJava programmingTopic:

When a subclass inherits from multiple superclasses, it is called multiple inheritance. However, Java does not support multiple inheritance.

To implement multiple inheritance in Java, we must use interfaces.

Example: Multiple Inheritance in Java

interface Backend {
  //Abstract class
  public void connectServer();
}
class Frontend {
  public void responsive(String str) {
    System.out.println(str + " can also be used as the frontend.");
  }
}
// Language inherits the Frontend class
// Language implements the Backend interface
class Language extends Frontend implements Backend {
  String language = "Java";
  //The implementation method of the interface
  public void connectServer() {
    System.out.println(language}} + "Can be used as a backend language.");
  }
  public static void main(String[] args) {
    // Creating an object of the Language class
    Language java = new Language();
    java.connectServer();
    //Calling the inherited method of the Frontend class
    java.responsive(java.language);
  }
}

Output Result

Java can also be used as a backend language.
Java can also be used as a frontend.

In the above example, we created an interface named Backend and a class named Frontend. The Language class inherits the Frontend class and implements the Backend interface.

Multiple Inheritance in Java

In this case, the Language class inherits the properties of Backend and Frontend. Therefore, it can be said that this is an instance of multiple inheritance.

Comprehensive Java Examples