What is the difference between an abstract class and an interface in Java?
Abstract classes and interfaces both enable abstraction, but they serve different design purposes.
An abstract class can contain instance fields, constructors, and a mix of abstract and concrete methods. A subclass extends it using extends and inherits its state and behavior. Java enforces single inheritance for classes — a class can extend only one abstract class. This makes abstract classes appropriate for modeling "is-a" relationships where subclasses share common state.
An interface defines a contract. Prior to Java 8, interfaces could only declare abstract methods and constants. Since Java 8, interfaces can include default methods and static methods. Java 9 added private methods. However, interfaces still cannot have instance fields or constructors — they cannot hold state. A class can implement multiple interfaces, enabling a form of multiple inheritance without the diamond problem.
Default methods narrowed the gap but did not eliminate it. They were designed to allow interface evolution — adding forEach() and stream() to Collection without breaking every implementation. But interfaces still cannot hold mutable state.
Use an abstract class when you need to share state among closely related classes, provide a partial implementation, enforce initialization via constructors, or use non-public members. Use an interface when you want to define a capability that can be mixed into unrelated classes — Comparable, Serializable, Iterable.
A practical pattern is to combine both: define interfaces for public API contracts and abstract classes as skeletal implementations. Java's List (interface) + AbstractList (abstract class) exemplifies this.
| Aspect | Abstract Class | Interface |
|---|---|---|
| Instance fields | Yes — can hold state | No — only constants (public static final) |
| Constructors | Yes | No |
| Method types | Abstract + concrete | Abstract + default (Java 8+) + static + private (Java 9+) |
| Inheritance | Single (extends one class) | Multiple (implements many interfaces) |
| Access modifiers | Any (public, protected, private, package) | Methods public by default; private since Java 9 |
| Design intent | "is-a" — shared identity and state | "can-do" — shared capability across unrelated types |
| Evolution | Adding methods may break subclasses | Default methods allow non-breaking additions |
Explains the core differences: state, constructors, single vs multiple inheritance. Mentions Java 8 default methods.
Covers state, constructors, inheritance model, access modifiers. Explains Java 8 default methods and their purpose. Provides clear decision criteria. References real-world examples like Collections Framework.
Reading the answer is step one. Explaining it unprompted — under interview pressure — is what actually matters. Get AI-graded feedback on your answer with follow-up probes on your weak points.
Get Graded — Free Assessment