<<Previous Question <<1500 Plus Interview Questions>> Next Question>>
Does Java supports multiple inheritance?
Watch the answer for this Selenium Interview Question in a detailed manner in the below youtube video:
Note: Don’t forget to subscribe to my Youtube channel here: Click here
Notes used for explanation in this Youtube video are provided after the video:
Notes used in the above Youtube Video:
The answer is Yes and No.
Multiple Inheritance is not supported in case of Classes:
In the case of Classes, a single class cannot inherit multiple classes due to the ambiguity problem.
Let’s say there are three classes i.e. ClassA, ClassB, and ClassC. Assume that ClassA and ClassB have a method having the same name say mOne(). In this case, if ClassC extends both ClassA and ClassC, then there is an ambiguity of inheriting mOne() from either ClassA or ClassB. i.e. Java cannot decide whether the mOne() can be inherited from ClassA or ClassB.
Hence multiple inheritance is not supported for Classes in Java.
Multiple Inheritance is supported in case of Interfaces:
In the case of Interfaces, a single class can inherit multiple interfaces as there is no ambiguity problem.
Let’s say there are two interfaces, i.e. InterfaceA, InterfaceB, and a class ClassC. Though InterfaceA and InterfaceB have a method with the same name say mOne(), ClassC can still inherit multiple interfaces, as mOne() method is not implemented in any of the interfaces.
Hence multiple inheritance is supported by Interfaces in Java.
Next Steps:
- > For more Selenium Interview Questions and answers, continue to the next post (Click on Next Post link below)
- > Check complete Selenium Interview Questions list here (Click here)
Please leave your questions/comments/feedback below.
Happy Learning ?
<<Previous Question <<1500 Plus Interview Questions>> Next Question>>
On a mission to contribute to the Software Testing Community in all possible ways.