Course contentsShow
← Java
Lesson 531 of 2,87012. Abstract Classes and InterfacesFree lesson

Combining Both: Abstract Classes Implementing Interfaces

How abstract classes can implement interfaces to provide partial implementations, reducing boilerplate for subclasses.

Combining Both: Abstract Classes Implementing Interfaces

What you'll learn: How to use abstract classes that implement interfaces to provide partial implementations, saving subclasses from repetitive code.

The Power of Combination

You've learned that interfaces define contracts and abstract classes provide shared implementation. But here's where they work beautifully together: an abstract class can implement an interface and provide implementations for some (or all) of its methods, while leaving others for concrete subclasses to complete.

This is like a restaurant franchise contract (interface) that requires every location to offer certain menu items and services. The regional management office (abstract class) handles the common operations—ordering supplies, training procedures, accounting—but leaves each individual restaurant (concrete subclass) to handle local customization like hiring and décor.

How It Works

When an abstract class implements an interface, it doesn't have to implement every method immediately. It can:

  • Implement some interface methods completely (reducing boilerplate for all subclasses)
  • Leave some methods abstract (forcing subclasses to provide specific behavior)
  • Add its own abstract or concrete methods beyond the interface

This creates a partial implementation that strikes a balance: the interface defines "what," the abstract class provides "some of how," and concrete subclasses complete "the rest of how."

Why This Matters

This pattern eliminates duplicate code. If five classes need to implement the same interface but share common logic, you write that shared logic once in an abstract class. Subclasses only override what's truly unique to them, while inheriting everything else.

Key Takeaway: Abstract classes implementing interfaces let you provide partial implementations of a contract, giving subclasses a head start with shared code while still enforcing that they complete the contract's requirements.