Interface or Abstract Class?

OOP · lesson 24 of 43 · 3 min read

A short decision procedure for choosing between an interface and an abstract class.

Open this lesson in the learning hub

Key points

  • Does the type need mutable instance state shared by every subclass? Only an abstract class can hold it.
  • Will one class need several of these roles at once? Only interfaces can be stacked, because you get one parent.
  • Do you need to fix the order of steps and leave holes? That is template method, and it wants an abstract class.
  • Just naming a capability, with maybe a shared helper? Interface, plus a default method if needed.
  • Modern Java leans to interfaces: they take lambdas, they compose, and they keep the single parent slot free.
  • When both fit, ship the interface and add a package-private abstract skeleton class for implementers who want it.

Abstract class for shared state and a fixed skeleton; interface for everything else.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the OOP course, and every lesson in it is listed on the OOP contents page.