+ 1

Why java doesn't support multiple inheritance?

4th Aug 2016, 6:07 AM
harshvardhan
7 Answers
+ 4
If a parent class has a method, and two subclasses have overridden that method, what method does the class that extends both those classes inherit?
4th Aug 2016, 10:11 AM
James
James - avatar
+ 3
Java chose not to support direct multiple inheritance due to ambiguity. The biggest reason, the diamond effect. You can still do multiple inheritance via interfaces though, it's just a different approach.
4th Aug 2016, 7:47 AM
James
James - avatar
+ 1
James, can you give example on how ambiguity?
4th Aug 2016, 10:02 AM
WPimpong
WPimpong - avatar
0
thanks
4th Aug 2016, 10:14 AM
WPimpong
WPimpong - avatar
0
you can use interface to inherit from multiple classes
16th Aug 2016, 9:36 AM
Ayush Vishwakarma
Ayush Vishwakarma - avatar
0
class left { void m1() { sop("m1-method of class left"); } } class Right { void m1() { sop("m1-method of class Right"); } } let's assume that Java supports multiple inheritance concept.and let's extend both left and Right classes. class Test extends left,Right { public static void main(String...args) { Test t = new Test(); t.m1(); } } Now can you say which class m1() method will be executed. the answer is you may not. in the same manner JVM also will get confused which class m1() method should it execute. conclusion: Because of ambiguity problems Java doesn't support multiple inheritance.
24th Aug 2016, 2:15 AM
Sarath chalapaka
Sarath chalapaka - avatar
0
It could just establish a hierarchy in the inheritance: class C extends A, B and both classes have a method dE could mean that C inherits the method from the second class (like, first C inherits from A, then B overrides some of its methods)
24th Aug 2016, 5:54 AM
Alberto Brandolini
Alberto Brandolini - avatar