Abstract class vs interface: what is the difference and when do you use each?
Short answer
An interface is a contract ("what it can do"); a class can implement many. An abstract class is an unfinished parent ("what it is"): it has state and constructors, but you can extend only one. Default to an interface.
3 points to say:
- Interface: implement many, no instance state.
- Abstract class: state, constructors, extend only one.
- Clashing default methods: override and pick with
A.super.hi().
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.