Multiple Inheritance


When the child class extends from more than one superclass, it is known as multiple inheritance.

However, Java does not support multiple inheritance. To achieve multiple inheritance in Java, we must use the interface. The example creates an interface named Backend and a class named Frontend. The class Language extends the Frontend class and implements the Backend interface. The Language class is inheriting the property of both Backend and Frontend.

Language.java (multiple inheritance)
// Java program to illustrate the concept of multiple inheritance 
// Language extends Frontend class.
// Language implements Backend interface.
class Language extends Frontend implements Backend {
  static int number;

  public static void main( String[ ] args ) {
    number = Integer.parseInt( args[0] );
    // Create object of Language class.
    Language java = new Language( );
    java.connectServer( );
    // Call the inherited method of Frontend class.
    java.responsive( java.number );
    System.out.println( number );
  }

  // Implement method of interface.
  public void connectServer( ) {
    number += number;
  }
}

interface Backend {
  // abstract class
  public void connectServer( );
}

class Frontend {
  public void responsive( int number ) {
    number += number;
  }
}
shell> java Language  

Output:           Result:




      After I was given my first camera    
      I was in seventh heaven (ecstatic).