Abstraction in Java — When to Use Abstract Class vs Interface
Fast recall
Quick revision
Core answer
protected methods — single inheritance only. Interface = capability (CAN-DO), multiple implementation, Java 8+ default methods. Decision rule: need shared instance fields or constructors? → abstract class. Defining a contract any class can fulfill? → interface (modern Java default). Adding a new abstract method breaks all subclasses; adding a default method to an interface is backward-compatible.Whether the candidate understands the design trade-off between abstract classes and interfaces — not just syntax differences, but when each is the right tool. Whether they know how Java 8 default methods blurred the line
Listing syntax differences without explaining when to choose each. Not knowing that interfaces can have default methods since Java 8, which eliminated the main advantage of abstract classes for many use cases
Explain that the real decision is about identity vs capability — abstract classes define what something IS, interfaces define what something CAN DO. Mention that a class can implement multiple interfaces but extend only one class, making interfaces the more flexible default
Interview-ready guide
Interview answer
Abstraction in Java means hiding the implementation details and exposing only what the caller needs to work with. Java provides two mechanisms for this: interfaces, which define a pure contract with no implementation, and abstract classes, which allow a mix of abstract methods and concrete shared behavior. The distinction between them matters most when designing extensible systems.
Interface — pure contract:
- An interface defines what an object can do, not what it is —
Comparable,Serializable,Runnabledescribe capabilities that any class can gain regardless of its inheritance hierarchy - A class can implement many interfaces, which is how Java compensates for the lack of multiple inheritance — behavior composes horizontally through interfaces
- Since Java 8, interfaces can carry
defaultmethod implementations — this was howCollection.stream()was added to millions of existing codebases without breaking anything
Abstract class — shared implementation:
- An abstract class makes sense when subclasses share mutable state (instance fields), initialization logic, or non-public helper methods that shouldn't be in an interface
- The template method pattern is the canonical use case: the abstract class defines the algorithm skeleton with abstract steps, and subclasses fill in the specific steps
Animalas an abstract class works becauseDogandCatgenuinely sharename,age, and common behavior — it's an IS-A identity, not just a capability
The Java 8 shift:
- Before Java 8, "do I need a method implementation?" was the deciding question — that answer always pointed to abstract classes
- After Java 8, the real question is: do you need shared state (instance fields) or constructors? Only abstract classes can have those; interfaces can now have method bodies
- Adding a new
defaultmethod to an interface is backward-compatible; adding a newabstractmethod to an abstract class immediately breaks every existing subclass
I recommend interfaces as the default in modern Java; reach for abstract classes only when you genuinely need shared mutable state or constructor logic that subclasses must run.
Abstraction in Java — When to Use Abstract Class vs Interface
Direct Answer
Abstract class = identity (IS-A), can have instance state, constructors, protected methods — single inheritance only. Interface = capability (CAN-DO), multiple implementation, Java 8+ default methods. Decision rule: need shared instance fields or constructors? → abstract class. Defining a contract any class can fulfill? → interface (modern Java default). Adding a new abstract method breaks all subclasses; adding a default method to an interface is backward-compatible.
Common Mistakes & Pitfalls
Listing syntax differences without explaining when to choose each. Not knowing that interfaces can have default methods since Java 8, which eliminated the main advantage of abstract classes for many use cases
Check your understanding
Answer these without looking back at the article.
- What changed about the abstract class vs interface decision after Java 8 added default methods?
- Can an interface have instance state (non-static fields) in Java?
- What is the template method pattern and why does it almost always use abstract classes instead of interfaces?
- If you add a new method to an interface with existing implementations, how do default methods solve the backward-compatibility problem?
- Why does Spring build almost everything on interfaces rather than abstract classes?
Related interview prep categories
1Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.