Interfaces Versus Abstract Classes

While you use an interface to specify the form that something must have, it does not actually provide the implementation for it. In this sense, an interface is a like an abstract class. The abstract class must be extended in exactly the manner that its abstract methods specify.

An interface differs from an abstract class in the following ways:

  • An abstract class is an incomplete class that requires further specialization in child classes. The subclasses are closely related to the parent. An interface doesn't have any overtones of specialization that are present with inheritance. It merely says, “We need something that does 'foo' and here are the ways that users should be able to call it.”

  • A class can ...

Get Just Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.