Course contentsShow
← Java
Lesson 437 of 2,87010. Inheritance FundamentalsFree lesson

is-a and Multiple Inheritance Through Interfaces

Recognize that a class can have multiple is-a relationships via interface implementation.

is-a and Multiple Inheritance Through Interfaces

What you'll learn: How a single class can satisfy multiple is-a relationships by implementing more than one interface, sidestepping Java's single-class inheritance limitation.


The Core Idea

You already know Java permits single inheritance only—a class can extends exactly one superclass. But what if an object logically "is" multiple things? For example, a FlyingFish is both an aquatic creature and a flyer.

Interfaces solve this by allowing a class to implement multiple contracts. Each implemented interface creates a distinct is-a relationship. When you write:

public class FlyingFish extends Animal implements Swimmer, Flyer {
    // ...
}

FlyingFish simultaneously satisfies three is-a relationships:

  • FlyingFish is-a Animal (inheritance)
  • FlyingFish is-a Swimmer (interface)
  • FlyingFish is-a Flyer (interface)

Each interface adds a capability or role without conflicting with single inheritance. You can use instanceof to test each relationship independently:

FlyingFish creature = new FlyingFish();
boolean test1 = creature instanceof Animal;   // true
boolean test2 = creature instanceof Swimmer;  // true
boolean test3 = creature instanceof Flyer;    // true

Why This Matters

Multiple interfaces model roles an object plays in different contexts. A Smartphone might be a Camera, a MusicPlayer, and a NetworkDevice all at once—impossible with classes alone, trivial with interfaces.

This flexibility is why interfaces are central to Java's polymorphism story: one object, many types, many client perspectives.


Key Takeaway:
A class can have multiple is-a relationships by implementing multiple interfaces, combining single inheritance with unlimited interface adoption.