javainterfacemultiple-inheritance

Inheriting from multiple classes in Java (and possibly not using interface)


So, let's say we have classes A, B and C and I want to inherit from all those classes and have another class called D, it can be done using implements and interfaces in Java. But let's say we don't want to use this simple solution, would you be able to inherit class D from classes A, B and C in any other way in Java?

(This question might be related to design patterns, it has been brought up after challenging my colleague at lunch discussing design patterns) I don't think there is any other way to have multiple inheritance in Java other than using multiple interfaces.


Solution

  • Multiple inheritance is not possible.

    Anyway, you could try to simulate such inheritance with composition.

    JB Nizet gave an answer to your question in the link provided.