What is the point of abstract classes, when you could just do an interface [duplicate]

A few points to consider:

  1. Interfaces didn’t have default methods until Java 8.

  2. That a in your interface is implicitly final. Interfaces can’t define public mutable fields.

  3. Interfaces can’t define private (or protected, or package) fields.

  4. Interfaces can’t have protected or package methods; they couldn’t have private methods until Java 9.

Abstract classes don’t have any of those issues. So when you need to do any of those things (other than #1, now that default methods exist), you reach for an abstract class (perhaps in addition to an interface that it implements).

Leave a Comment