What is the difference between an abstract class and an interface in Java?
An abstract class can have constructors, fields, and both finished and unfinished methods, and a class can extend only one. An interface defines a contract, can have default and static methods since Java 8, cannot hold instance state, and a class can implement many. Use an abstract class for a shared base, and an interface for a capability shared across unrelated classes.
- An abstract class can hold state and mix finished and abstract methods, and a class extends only one.
- An interface is a contract, and a class can implement many interfaces.
- Since Java 8 interfaces can have default methods, narrowing the old gap between the two.
Key differences
- Inheritance: one abstract class can be extended, many interfaces can be implemented.
- State: abstract classes hold instance fields, interfaces hold constants only.
- Constructors: abstract classes have them, interfaces do not.
- Methods: since Java 8 interfaces can have default and static method bodies.
interface Flyer {
default void takeOff() { System.out.println("lifting off"); }
}
abstract class Bird {
abstract void sing();
}
Mention that Java 8 default methods blurred the line, but the big rule remains: you can implement many interfaces but extend only one class. Use interfaces to model capabilities and abstract classes to share base behaviour.
Frequently asked questions
Can an interface have method bodies now?
Yes. Since Java 8 interfaces can have default and static methods with bodies, and since Java 9 they can have private methods too.
When should you use an abstract class in Java?
Use one when related classes share common fields and some implemented behaviour, and you want a single base type for them.
Common follow up questions
Related interview questions
Want the full Java guide?
Read every Java concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the Java guide All Java questions