Java - Interface Interface Inheritance

Introduction

An interface can inherit from another interface.

An interface can inherit from multiple interfaces.

Example

For the following interface

interface Singer {
        void sing();
        void setRate(double rate);
        double getRate();
}
interface MySpecialSinger extends Singer {
}

MySpecialSinger interface inherits the three abstract methods from the Singer interface.

Any class implementing the MySpecialSinger interface will need to implement those three methods.

Demo

interface Singer {
  void sing();//from   w w  w  .  j ava  2s . co m

  void setRate(double rate);

  double getRate();
}

interface MySpecialSinger extends Singer {
}
class ASinger implements MySpecialSinger{

  @Override
  public void sing() {
    
  }

  @Override
  public void setRate(double rate) {
    
  }

  @Override
  public double getRate() {
    return 0;
  }
  
}
public class Main {
  public static void main(String[] args) {

  }

}


interface Writer {
        void write();
        void setRate(double rate);
        double getRate();
}
interface Player {
    void play();
    void setRate(double rate);
    default double getRate() {
        return 300.0;
    }
}