Forums Register Login

Java does not support multiple inheritance...?

+Pie Number of slices to send: Send
Hi Friends can anyone explain me how Java does not support multiple inheritance?

If a class inherits properties of more than one class then it is called multiple inheritance.

In Java, all classes extends Object class implicitly. Condsider a class B which extends class A. Here class B implicitly extends Object class. In this scenario class B inherit the properties of both class A as well as class Object, so this should be considered as multiple inheritance but we consider that java does not support multiple inheritance, why...?

-Som
+Pie Number of slices to send: Send
 

In Java, all classes extends Object class implicitly. Condsider a class B which extends class A. Here class B implicitly extends Object class. In this scenario class B inherit the properties of both class A as well as class Object, so this should be considered as multiple inheritance but we consider that java does not support multiple inheritance, why...?



The definition of multiple inheritance is the ability to inherit from multiple classes (from different hierachies). For example, if class B extends from class A, and class C extends from class A. Mulitple inheritance is the ability to inherit from both class B and C.

Henry
+Pie Number of slices to send: Send
 


In Java, all classes extends Object class implicitly. Condsider a class B which extends class A. Here class B implicitly extends Object class. In this scenario class B inherit the properties of both class A as well as class Object, so this should be considered as multiple inheritance but we consider that java does not support multiple inheritance, why...?



I think the difference is java doesn't support mulitple inheritance "explicitly." Like in c++ a class of the following can work..

class c extends A, B
()
{}

but this doesn't work in Java. Although class C is implicitly the subclass of its superclass class A, in other scenarios of "classing", it will not work.

Interface is the counterpart of inheritance in Java so we can still use the properties of the superclass of our class program.
+Pie Number of slices to send: Send
Probably best to say that interfaces mimic multiple inheritance, and A----->B----->C is called single inheritance.

It would only be multiple inheritance if you could draw a diagram like this
today's feeble attempt to support the empire
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3758 times.
Similar Threads
Doubt in Multiple inheritance
Java doesn't support multiple inheritance rather it supports multi-level inheritance
Does Java Support Multiple Inheritance
Multiple Interface Inheritance / Interface Inheritance
Java Doesn't support Multiple inheritance
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:46:41.