Default Methods vs Abstract Methods in Interfaces
Fast recall
Quick revision
Core answer
Clear distinction between the two types of interface methods and when to use each.
Confusing default methods with abstract methods or thinking default still means must implement.
Explain the design decision: use abstract for mandatory contract, default for optional extensions.
Interview-ready guide
Interview answer
An abstract interface method declares a required operation but has no body. A concrete implementing class must declare or inherit a compatible implementation. A default method already has a body in the interface, so the class normally inherits it and may override it. For example, PaymentProcessor.pay can be abstract because card and bank implementations perform different work, while a default formatReceipt can reuse shared formatting. Java 8 also used default methods to evolve established interfaces: Iterable gained forEach, and Collection gained stream. That improved compatibility for existing implementations, although competing inherited defaults and behavior changes still need review.
Default Methods vs Abstract Methods in Interfaces
Direct Answer
An abstract interface method declares a required operation without a body; a concrete implementing class must supply or inherit a compatible implementation. A default method has an interface body that is inherited when no class method, more-specific override, or unresolved default conflict takes precedence.
Code Example
public class DefaultVsAbstractMethod {
interface Payment {
void pay(double amount); // abstract: every impl MUST define it
default void refund(double amount) { // default: optional shared behavior
System.out.println("Refunding " + amount);
}
}
static class CardPayment implements Payment {
public void pay(double amount) { // required
System.out.println("Charging card " + amount);
}
// refund() is inherited from the default method
}
public static void main(String[] args) {
Payment p = new CardPayment();
p.pay(100); // Charging card 100.0
p.refund(40); // Refunding 40.0
}
}
Common Mistakes & Pitfalls
- Confusing terminology: Freshers see "default method" and think it means a default abstract method that you still have to implement, mixing up "default" with "must have a default." It's actually a method with a default implementation you inherit.
- Making everything default: Some freshers avoid abstract methods entirely and make everything default, thinking it's more flexible. This breaks the contract model — if findById is default with an empty implementation, you've lost the enforcement that repositories must provide lookup.
- Not leveraging abstract in defaults: Freshers write default methods that duplicate logic instead of calling the abstract methods. A default findAll should call the abstract findById, not reimplement database access.
Check your understanding
Answer these without looking back at the article.
- Can a functional interface have default methods?
- What is the difference between default methods and final methods?
- Can default methods be private in Java 9?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.