#6.3 Java Tutorial | Multiple Inheritance in Java?

preview_player
Показать описание
In this lecture we are discussing:
1)what is multiple inheritance?
2)Why Java does not support Multiple Inheritance?
3)What is ambiguity and not allowed in java?

#1
Multiple inheritance
If a particular class inheriting multiple class then this type of inheritance is called multiple inheritance.
like c++ language there are multiple inheritance like that :
class A
{
... .. ...
};
class B
{
... .. ...
};
class C: public A,public B
{
... ... ...
};

But Java not allowed we have alternate option for that is implementing multiple interface not we will discussing in upcoming lecture.
#2
why java not support multiple inheritance?
:- Because of the Ambiguity problem, Java does not support multiple inheritances directly.

#3
Why it is ambiguous?
suppose we have some class A, B and c
class A
{
... .. ...
show(){

}
};
class B
{
... .. ...
show(){

}
};
class C extends A,B //assume for some instance java support multiple inheritence
{
... ... ...
show();
//here we get ambiguity since if we allowed multiple inheritance and same two property or method belong to class A and Class B
//then how C class use show() method there is ambiguity of choice...
//that’s why java exclude the concept of multiple inheritance

};

More Learning :

Donation:
PayPal Id : navinreddy20
Patreon : navinreddy20
Рекомендации по теме
Комментарии
Автор

Very useful lesson, although I was hoping you would go in depth about implementing multiple interfaces, because it is similar to multiple inheritance of pure abstract classes in other languages like C++.

doonk
Автор

Can interface use for multiple inheritance?

kirankhemnar
Автор

Sad, it doesn't support this directly. The sensible solution would be to call the parent class method by default, bypassing the inherited "overwrites"; thereby granting the programmer the chance to overwrite the parent method for the multi inherited class.

chevalierdeloccident
Автор

Operator overiding ka concept ho jyga na

prateekjain
Автор

Not perfect reason! What if I don't give same methods in both class. Then I should be able to use multiple inheritance!

atharvabhatkhalkar