INHERITANCE
What is Inheritance?
Extending the parent class properties. It will inherit all the methods and properties
Note: By default every class is a subclass of Object class.
How may types of inheritance are present?
i) Single level inheritance:
ii) Multi level inheritance:
iii)Multiple inheritance: One class is extending 2 classes
iv)Hierarchal inheritance: One parent have might have many childs
Why java doesn't support multiple inheritance?
There will be an Ambiguity issue. Consider there are 3 Classes A,B,C and there is show() method in A and B and C extends A and B. Now if we create a object for Class C and then call the show() method, It will confuse which method to call because the method exists in both the classes. So java doesn't support Multiple Inheritance. But we can make this happen using Interfaces
C extends A,B
Comments
Post a Comment