Why multiple inheritance is not supported in java?
Multiple inheritance is not supported in java through class to prevent situations arising out of ambiguity.
Lets understand the same with example.
Suppose two classes which are inherited by any third class (or child class) has method with same name.
If that method is called from child class then which classes method should be called is not clear in this case. So this creates a ambiguous scenario.
For example, consider below image of multiple inheritance given below.
Suppose class Science and class Commerce both has method "formFillUp()".
Admission class inherits both the class Science and class Commerce.
Now if we try to call or use "formFillUp()" method from within Admission class then we have a question arising for us.
Which class "formFillUp()" method is called?
Since by the property of inheritance class Admission has access to both classes method so it will be difficult for it to decide which one to call.
This is the ambiguity we were indicating to so far.
To help reduce the chances of such situations arising java does not support multiple inheritance.
Thus java doesn't support multiple inheritance through class.
However, we can implement multiple inheritance using concept of java interface.
We have already explained this with an example and diagrammatic explanation in our inheritance chapter of java tutorial.
Click here to learn in depth
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Sonu Pandit
I am editor in chief at tutorialsinhand.com responsible for managing, reviewing and sending articles/contents for final approval to get published. Connect with me@https://www.linkedin.com/in/sonu-pandit-a77b471ab/. Join write4us program & share your skill
Page Views :
Published Date :
Jul 12,2020