Abstract Class vs. Interface

0. Introduction
Since Java 8 introduced default methods in interfaces, many developers wondered: Do we still need abstract classes? While interfaces have become more powerful, abstract classes continue to play an important role in Java’s type system. This post explains the difference and when to use each.
1. Multiple Inheritance
Interface: allows multiple implementations (
implementsmany)Abstract class: only single inheritance (
extendsone)
👉 Use abstract class when you need to share a strict class hierarchy.
2. State (Fields)
Interface: only
static finalconstants, no instance fieldsAbstract class: can have instance fields, constructors, and access modifiers
👉 Use abstract class when you need to manage shared state or utility fields.
3. Constructors
Interface: cannot have constructors
Abstract class: can define constructors to enforce initialization logic
4. Access Modifiers
Interface: methods are implicitly
public(default methods too)Abstract class: supports
protected,private, and package-private
👉 Useful for hiding common logic from external access.
5. Default Method Conflicts
If multiple interfaces define the same default method, you must explicitly override it.
Abstract classes avoid this problem due to single inheritance.
6. When to Use
Interface (with default methods)
Define behavior or capabilities (e.g.,
Comparable,Runnable)When multiple inheritance of behavior is required
When no shared state or initialization is needed
Abstract Class
Share state (fields) and implementation
Enforce constructors and initialization logic
Control method visibility with access modifiers
Best for strong hierarchical relationships
7. Comparison Table
| Feature | Interface (with default methods) | Abstract Class |
| Multiple Inheritance | A class can implement multiple interfaces | A class can extend only one abstract class |
| Fields | Only public static final constants allowed | Instance fields allowed |
| Constructors | Not allowed | Can define constructors for initialization |
| Access Modifiers | Methods are implicitly public (default methods too) | Supports public, protected, private, and package-private |
| State Management | Cannot hold instance state | Can manage and share state across subclasses |
| Default Method Conflicts | Must override if multiple interfaces provide same default method | No conflict since single inheritance |
8. Usage Summary
| Use Case | Prefer Interface | Prefer Abstract Class |
| Define behavior without state | ✅ | |
| Multiple inheritance of behavior | ✅ | |
| Common state/fields required | ✅ | |
| Require constructors | ✅ | |
| Fine-grained access control (protected, private) | ✅ | |
| Avoid default method conflicts | ✅ |
✨ Conclusion
Default methods in interfaces expanded their power, but abstract classes are still necessary when state, initialization, or strict hierarchy are required.
Use interfaces to define contracts and allow flexibility.
Use abstract classes when you need shared state, constructors, or controlled access.





