6 B (I) Java and Multiple Inheritance
6 B (I) Java and Multiple Inheritance
Related Articles
Multiple Inheritance is a feature of object oriented concept, where a class can inherit
proper ties of more than one parent class. The problem occurs when there exist
methods with same signature in both the super classes and subclass. On calling the
method, the compiler cannot determine which class method to be called and even on
Output :
Compiler Error
From the code, we see that, on calling the method fun() using Test object will cause
The below Java program throws compiler error when run. Multiple inheritance causes
Ad
GrandParent
/ \
/ \
Parent1 Parent2
\ /
\ /
Test
https://www.geeksforgeeks.org/java-and-multiple-inheritance/ 2/8
9/1/2021 Java and Multiple Inheritance - GeeksforGeeks
Output :
Error :
1 error
From the code, we see that: On calling the method fun() using Test object will cause
Therefore, in order to avoid such complications Java does not suppor t multiple
inheritance of classes.
2. Simplicity – Multiple inheritance is not suppor ted by Java using classes , handling
the complexity that causes due to multiple inheritance is ver y complex. It creates
We use cookies
problem to ensure
during you haveoperations
various the best browsing experience
like casting,on our website. By using
constructor our site, you
acknowledge
chaining that
etc and the above
Got It !
inheritance, so better to omit it for keeping the things simple and straightfor ward.
https://www.geeksforgeeks.org/java-and-multiple-inheritance/ 3/8
9/1/2021 Java and Multiple Inheritance - GeeksforGeeks
How are above problems handled for Default Methods and Inter faces ?
Java 8 suppor ts default methods where inter faces can provide default implementation
of methods. And a class can implement two or more inter faces. In case both the
implemented inter faces contain default methods with same method signature, the
https://www.geeksforgeeks.org/java-and-multiple-inheritance/ 4/8
9/1/2021 Java and Multiple Inheritance - GeeksforGeeks
Output:
Default PI1
Default PI2
If there is a diamond through inter faces, then there is no issue if none of the middle
inter faces provide implementation of root inter face. If they provide implementation,
Output:
Default GPI
This ar ticle is contributed by Vishal S. If you like GeeksforGeeks and would like to
We use ar
your cookies
ticletoto
ensure you have the best browsing experience on See
contribute@geeksforgeeks.org. our website.
your By arusing
ticleour site, you
acknowledge
appearing on the that
Got It !
https://www.geeksforgeeks.org/java-and-multiple-inheritance/ 5/8
9/1/2021 Java and Multiple Inheritance - GeeksforGeeks
Please write comments if you find anything incorrect, or you want to share more
Attention reader! Don’t stop learning now. Get hold of all the impor tant Java
Foundation and Collections concepts with the Fundamentals of Java and Java
complete your preparation from learning a language to DS Algo and many more,
Like 0
Previous Next
https://www.geeksforgeeks.org/java-and-multiple-inheritance/ 6/8
9/1/2021 Java and Multiple Inheritance - GeeksforGeeks
Ar ticle Contributed By :
GeeksforGeeks
Current difficulty :
Medium
https://www.geeksforgeeks.org/java-and-multiple-inheritance/ 7/8
9/1/2021 Java and Multiple Inheritance - GeeksforGeeks
Company Learn
About Us Algorithms
Careers Data Structures
Privacy Policy Languages
Contact Us CS Subjects
Copyright Policy Video Tutorials
@geeksforgeeks
, Some rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that
you have read and understood our
Cookie Policy &
Privacy Policy
Got It !
https://www.geeksforgeeks.org/java-and-multiple-inheritance/ 8/8