# Solving Multiple Inheritance

Java allows only one parent class, so interfaces let a class take on more than one set of abilities without the problems of multiple inheritance.

Journeyman · Java · OOP · Updated November 16, 2026

By Gregor Dzierzon

An interface is like a 100% abstract class. So, if interfaces are just special classes, why do we need them?

Many OOP languages that do not support interfaces allow child classes to inherit from multiple parent classes.

![Multiple inheritance](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/09/6ff4c3c4606644268274cab638e1869f.png "Multiple inheritance")

This can lead to unexpected coding challenges that you now have to deal with. For instance, if you create a riding mower and then turn it on, which parent `turnOn()` method should be called, or should they both be called?

```java
RidingMower lawnRider = new RidingMower("Meadow Pro","5500",500);
lawnRider.turnOn();
```

Because this challenge of dealing with multiple inheritance often resulted in buggy code, a pattern that emerged in OOP was that developers would create **one** primary parent class from which a child could inherit variables and methods. Then, if a class needed to inherit from another class, additional parents would be designed as fully abstract classes. This way, potential method naming collisions could be avoided.

Java took this approach one step further. In Java, and in several other modern OOP languages, it is illegal to extend more than one parent class.

![Java only allows single inheritance](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/09/39b7669d86c04feb926aebf882396f86.png "Java only allows single inheritance")

## Adding Interfaces

Java only allows you to inherit from a single class, but, you can implement as many interfaces as you need. By introducing the interface construct, Java ensured that the additional "inherited classes" would be 100% abstract.

![RidingMower implements multiple interfaces](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/09/2d3aeb0f4f69434dbab94721b2abce63.png "RidingMower implements multiple interfaces")

## Do it: one turnOn for two interfaces

The riding mower is set up the Java way: one parent class, `Machine`, which gives it its make, and two interfaces after it, `Drivable` and `BladeController`. Both interfaces ask for a `turnOn()` method. **The starter doesn't compile yet**: Java says `RidingMower` doesn't write the interfaces' methods. Your job is to write them.

The two interfaces are given at the bottom of the file (the next lesson shows how to write your own):

- `Drivable` asks for `String turnOn()` and `String steer(String direction)`.
- `BladeController` asks for `String turnOn()`.

A class keeps an interface's contract by writing each of its methods as an ordinary `public` method, with the same name, parameters and return type.

For example, a Meadow Pro mower:

```java
RidingMower mower = new RidingMower("Meadow Pro");
```

| Call | Returns |
|---|---|
| `mower.turnOn()` | `"Meadow Pro is running"` |
| `mower.steer("left")` | `"Turning left"` |

**Your job:** write the methods the two interfaces ask for in `RidingMower`.

- Write **one** `public String turnOn()`. It returns the mower's make, then `" is running"`. That one method keeps both interfaces' contracts.
- Write `public String steer(String direction)`. It returns `"Turning "`, then the direction.
- Leave `Machine`, the two interfaces and `RidingMower`'s first line as they are.

Practiced live on the lesson page: write the Java right there and check it.

## Cheat sheets

- [Solving Multiple Inheritance](https://www.ask-codey.com/cheat-sheets/abstraction-through-interfaces-solving-multiple-inheritance-cheat-sheet)

Source: https://www.ask-codey.com/lessons/abstraction-through-interfaces-solving-multiple-inheritance
