Lesson 11: Abstract Classes vs Interfaces
12 Jul 2026 1 min Swarnil Singhai
Abstract classes share partial implementation among related types; interfaces define a contract any unrelated type can fulfill.
Real-time example
A payments app has an interface PaymentMethod implemented by unrelated classes: CreditCard, UPI, Wallet — they share no code, only a contract.
interface PaymentMethod {
boolean charge(double amount);
}
class UPI implements PaymentMethod {
public boolean charge(double amount) {
System.out.println("UPI charged Rs " + amount);
return true;
}
}
class CreditCard implements PaymentMethod {
public boolean charge(double amount) {
System.out.println("Card charged Rs " + amount);
return true;
}
}
What's happening
Any class, regardless of its inheritance tree, can implements PaymentMethod — interfaces cut across unrelated hierarchies.
Rule of thumb: interface for 'can do X', abstract class for 'is a kind of X with shared logic'.
Advertisement