OOP · Advanced OOP
Interface
Imagine you're developing an Online Payment System.
Real-World Problem
Imagine you're developing an Online Payment System. Different payment methods such as UPI, Credit Card, Debit Card, and Net Banking all perform the same operation—Make Payment. Although the implementation varies, every payment method must provide this functionality. Java uses Interfaces to define this common contract.
Why Do We Need an Interface? Different classes may perform the same operation in different ways. An interface provides a common contract that every implementing class must follow without forcing them to share implementation. This promotes flexibility, loose coupling, and multiple inheritance.

What is an Interface? An Interface is a blueprint that defines a set of methods which implementing classes must provide. It specifies what a class should do, but not how it should do it. Interfaces are primarily used to achieve complete abstraction and multiple inheritance in Java.

Characteristics
- Declared using the interface keyword.
- Cannot be instantiated.
- Methods are public and abstract by default.
- Variables are public, static, and final.
- Supports multiple inheritance.
- Implemented using the implements keyword.
Basic Interface
Multiple Interface Implementation


An interface is a pure contract of behavior any class can promise to fulfill.
interface Notifier {
void send(String message); // what, not how
}
class EmailNotifier implements Notifier {
public void send(String message) {
System.out.println("Email: " + message);
}
}
class SmsNotifier implements Notifier {
public void send(String message) {
System.out.println("SMS: " + message);
}
}
// Both are interchangeable wherever a Notifier is expected.