“In the last lectures, we learned interfaces and abstract classes separately.
You already know that interfaces define rules and abstract classes provide partial
implementation.”
But today we are going one level deeper.
Today’s lecture answers three very important questions:
1. Can interfaces use inheritance?
2. How is interface inheritance different from class inheritance?
3. What are functional interfaces, and why Java introduced them?
This lecture is extremely important, especially if you want to:
• Write clean architecture
• Understand Java 8+
• Work with Spring Boot, Streams, Lambdas
So relax, focus — and let’s begin.
PART 1 — Why We Need Inheritance in Interfaces (Problem First)
Problem Without Interface Inheritance
Imagine we are building a payment system.
We have different services:
• ATM Payment
• Online Payment
• Mobile App Payment
All of them:
• Authenticate user
• Process payment
So we create an interface:
,interface Payment {
void authenticate();
void pay();
}
So far, so good.
New Requirement Appears
Now business says:
“Some payment methods also support refunds.”
Question:
• Should we rewrite the Payment interface?
• Should all payment systems support refund?
NO.
Solution: Interface Inheritance
We extend one interface from another.
PART 2 — Interface Inheritance Explained
Base Interface
interface Payment {
void authenticate();
void pay();
}
This is the parent interface.
, Child Interface (Inheritance in Interface)
interface RefundablePayment extends Payment {
void refund();
}
Instructor Explanation
“Notice something powerful here:
An interface can extend another interface.”
• RefundablePayment inherits rules of Payment
• Any class implementing RefundablePayment MUST implement:
o authenticate()
o pay()
o refund()
Class Implementing Parent Interface
class ATM implements Payment {
public void authenticate() {
System.out.println("ATM authentication using PIN");
}
public void pay() {
System.out.println("ATM payment processed");
}
}
Class Implementing Child Interface
, class OnlinePayment implements RefundablePayment {
public void authenticate() {
System.out.println("Online authentication using OTP");
}
public void pay() {
System.out.println("Online payment done");
}
public void refund() {
System.out.println("Online payment refunded");
}
}
Instructor Explanation
“ATM does NOT support refund, so it implements Payment.
Online payment DOES support refund, so it implements RefundablePayment.”
This is clean design.
IMPORTANT RULES ABOUT INTERFACE INHERITANCE
Instructor speaking slowly and clearly:
• An interface can extend multiple interfaces
• A class can implement multiple interfaces
• Interfaces do NOT have constructors
• Interface inheritance is 100% abstract