Java ProgramsOOPInterface Inheritance

Interface Inheritance in Java

intermediate·  OOP  ·  Interfaces

Problem

An interface can extend another interface, inheriting its method signatures and adding more of its own — a class implementing the child interface must supply methods from both.

Define a RefundablePayable interface that extends Payable, and implement it in a single class.

Input
amount = 100.0
Output
Paid: 100.0 Refunded: 100.0

Java Program

Java
interface Payable { void pay(double amount); } interface RefundablePayable extends Payable { void refund(double amount); } class Order implements RefundablePayable { public void pay(double amount) { System.out.println("Paid: " + amount); } public void refund(double amount) { System.out.println("Refunded: " + amount); } } public class InterfaceInheritanceDemo { public static void main(String[] args) { Order order = new Order(); order.pay(100.0); order.refund(100.0); } }

Output

Paid: 100.0 Refunded: 100.0

Core Logic

Extending one interface from another folds the parent's method signatures into the child, so a class implementing only the child ends up responsible for both.

How It Works
  1. 1interface Payable declares void pay(double amount);.
  2. 2interface RefundablePayable extends Payable adds void refund(double amount); on top of the inherited pay.
  3. 3class Order implements RefundablePayable must supply both pay() and refund(), even though only refund() is declared directly on the interface it names.
  4. 4Calling either method on an Order object runs the matching implementation.
Calling order.pay(100.0) then order.refund(100.0) runs both implementations in turn, printing "Paid: 100.0" and "Refunded: 100.0".
💡

Key Point: Unlike classes, interfaces can extend more than one other interface at once — a child interface can pull in method signatures from several parents simultaneously.

Key Concepts

interface extends interfaceimplementsinherited abstract methods

Related Programs