All topics
library
beginner

Abstract Classes vs Interfaces

Know exactly when to choose an abstract class over an interface — a top-5 Java interview question.

This is one of the most frequently asked Java interview questions, and the answer has evolved since Java 8.

Abstract class = partially assembled IKEA shelf. Interface = a blueprint saying 'must have shelves and doors' — build however you want, follow multiple blueprints.

Key Concepts

1
Modern decision criteria:
2
1. State: If subtypes need shared instance fields, use abstract class. Interfaces cannot have instance state. 2. Constructors: Abstract classes have constructors; interfaces don't. 3. Multiple inheritance: A class can implement many interfaces but extend only one class. For capabilities that unrelated classes share, use interface. 4. Evolution: Adding a default method to an interface is backward-compatible. Adding abstract method to abstract class breaks all subclasses. 5. Access control: Abstract classes support all access modifiers. Interface methods are implicitly public.
3
The modern rule: prefer interfaces for defining types and capabilities. Use abstract classes only when you need shared state, constructors, or non-public methods. Many pre-Java-8 abstract classes (AbstractList) would be interfaces if designed today.