Course Content
Core Java
About Lesson

Interface inheritance allows one interface to inherit the methods and constants of another interface. This mechanism enables the creation of a hierarchy of interfaces, where a subclass interface inherits the behavior of its superclass interface.

  1. Superinterface: An interface that is extended by another interface is referred to as a superinterface.
  2. Subinterface: An interface that extends another interface is referred to as a subinterface.
  3. Extending Syntax: Use the extends keyword to indicate interface inheritance.

Implementing Interfaces with Inheritance

Classes implementing a subinterface must provide implementations for all methods defined in both the subinterface and its superinterfaces.

// Base interface
public interface Movable {
    void move();
}

// Derived interface
public interface Flyable extends Movable {
    void fly();
}

// Implementing the derived interface
public class Airplane implements Flyable {
    @Override
    public void move() {
        System.out.println("Airplane is moving on the runway.");
    }

    @Override
    public void fly() {
        System.out.println("Airplane is flying.");
    }
}

public class Main {
    public static void main(String[] args) {
        Airplane airplane = new Airplane();
        airplane.move(); // Output: Airplane is moving on the runway.
        airplane.fly(); // Output: Airplane is flying.
    }
}

Scroll to Top