An interface states a contract and nothing else. An abstract class states a contract plus part of the implementation. It can hold fields, constructors and finished methods that subclasses share.
A class can implement many interfaces but extend only one abstract class. That makes an interface cheap to add to a type that already has a parent.
An abstract class can carry state and enforce an order of steps.
Classes from unrelated hierarchies can implement the same interface.
Some languages now let interfaces carry default method bodies. State and constructors still belong to classes. The choice comes down to whether subclasses share code, or only share a capability that callers depend on.
Rewriting in plainer words…
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Saved in this browser - sign in to keep your review list.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Keep going - a few more words and AI can grade it.
Interview lens
How interviewers actually use this question
Likely follow-ups
Should a new class hierarchy start from an interface or an abstract class?Start from the interface callers depend on. Add an abstract base under it only when implementations really share code or state.
Why do most languages allow many interfaces but only one base class?Two base classes can bring clashing fields and constructor order. A contract with no state has little to clash, so a class can stack many.
If interfaces can have default methods, what can an abstract class still do that an interface can't?Name instance fields and constructors. A default method has no per-object fields of its own to read or write.
Two interfaces give one class the same default method. What happens, and how is it resolved?Name the diamond problem. The usual rule is that the class must override the clashing method and can call one parent's version.
How would an abstract class make subclasses run steps in a fixed order?Name the template method pattern. A non-overridable method calls abstract hooks in a set order, so subclasses fill in steps but can't reorder them.
What you can say
An interface is only a contract, while an abstract class is a contract plus part of the implementation.
So an abstract class can hold fields, constructors and finished methods that every subclass shares, and it can enforce an order of steps.
A class can implement many interfaces but extend only one abstract class, so an interface is cheap to add to a type that already has a parent.
That also means classes from unrelated hierarchies can implement the same interface.
Some languages now let interfaces carry default method bodies, but state and constructors still belong to classes.
My rule is that shared code points to an abstract class, but if subclasses only share a capability callers depend on, I use an interface and keep the one parent slot free.
Weak answers to avoid
Says interfaces can never have method bodiesMany languages now allow default methods, so this sounds dated. Say interfaces can carry defaults but still hold no state or constructors.
Recites keywords instead of the design choiceModifier rules are trivia. Say when you'd pick each one, shared code versus a capability callers depend on, and mention the one-parent limit.
Claims an abstract class has no constructorYou can't create one directly, but its constructor runs when a subclass is created and sets up the shared fields.
Uses an abstract class just to share a capabilityThat uses up the only parent slot and shuts out types that already have a parent. Use an interface when subclasses share no code or state.
Interview lens
Likely follow-ups, what you can say, and the weak answers to avoid.