In Object Oriented Programming Language there are certain things that need to satisfy a programming language to become an OOP language. Like Abstraction, Polymorphism, Inheritance, Encapsulation etc. So Inheritance is one of the most important pillars of OOP language. The main concept behind this is with the help of old class we can make new class or classes. The advantage of using this is code reusability. Means you need not to write the same code again and again in the new class that has already been written in another class.
Types :
Inheritance is a process of getting the properties (Methods and variables) of a class (Parent Class) by another class (Child Class) by extending the class. Keyword we use is "extends". Inheritance follows IS-A relationship. There are different types of Inheritance. Like,
Single Inheritance:
One Class Inherits another class.
Multilevel Inheritance :
When there is a chain of inheritance that is Multilevel Inheritance.
Multiple Inheritance :
One Class can Inherit from more than one class, but it is not supported in Java. In Java compiler can't determine which class method needs to be called or whom to give more priority.
Hierarchical Inheritance:
More than one class inherit another class.
Hybrid Inheritance :
More than One type of Inheritance together is called Hybrid Inheritance.
Post a Comment
0 Comments