Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 864
sheidaei Avatar asked Sep 20 '25 11:09

sheidaei


1 Answers

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.

like image 118
LaGrandMere Avatar answered Sep 23 '25 00:09

LaGrandMere