Learn-Object_Oriented_programming-with-us
Learn By Topic:
Class-objects
Inheritance
Polymorphism
Encapsulation
Abstraction
Click here to toggle b/w normal and focus mode: NORMAL MODE
What is Inheritance?
Inheritance is one of the core concepts of object-oriented programming (OOP) languages. It is a mechanism where you can to derive a class from another class for a hierarchy of classes that share a set of attributes and methods.
For example, herding dogs have the unique ability to herd animals. In other words, all herding dogs are dogs, but not all dogs are herding dogs. We represent this difference by creating a child class HerdingDog from the parent class Dog, and then add the unique herd() behavior. This might sound a little bit confusing at the start , trust me you'll get through with the conecpt in later sections
The benefits of inheritance are programs can create a generic parent class, and then create more specific child classes as needed. This simplifies overall programming, because instead of recreating the structure of the Dog class multiple times, child classes automatically gain access to functionalities within their parent class.
Advantages of Inheritance
Below are listed a few pros of inheritance:
With the help of inheritance, we need not create and define data members and functions recursively. We code once in a class, and they can inherit all properties of data members and functions in the subsequent subclass. This feature also helps in effective dynamic programming.
Frequent use of code written once, i.e. code reusability.
One superclass can be used for the number of subclasses in a hierarchy.
No changes to be done in all base classes; just do changes in parent class only.
Inheritance is used to generate more dominant objects.
Inheritance avoids duplicity and data redundancy.
Inheritance is used to avoid space complexity and time complexity.
Different Types of Inheritance
OOPs support the five different types of inheritance as given below :
Single inheritance
Multi-level inheritance
Multiple inheritance
Hierarchical Inheritance
Hybrid Inheritance
Single inheritance
In this inheritance, a derived class is created from a single base class.
In the given example, Class A is the parent class and Class B is the child class since Class B inherits the features and behavior of the parent class A.

Multi-level inheritance
In this inheritance, a derived class is created from another derived class.
In the given example, childClass_1 inherits the properties and behavior of ParentClass and ChildClass_2 inherits the properties and behavior of ChildClass_1 . So, here ChildClass_1 is the parent class of ChildClass_2 and class ParentClass is the parent class of ChildClass_1. So, here class ChildClass_2 implicitly inherits the properties and behavior of class ChildClass_1 along with Class ParentClass i.e there is a multilevel of inheritance.

Multiple inheritance
In this inheritance, a derived class is created from more than one base class. This inheritance is not supported by .NET Languages like C#, F# etc. and Java Language.
In the given example, ChildClass inherits the properties and behavior of ParentClass_1 and ParentClass_2 at same level. So, here ParentClass_1 and ParentClass_2 both are the parent classes for ChildClass.

Hierarchical Inheritance
In this inheritance, more than one derived classes are created from a single base class and futher child classes act as parent classes for more than one child classes.
In the given example, ParentClass has two childs class's i.e ChildClass_1 and ChildClass_2 . From a single parent class more than one child class inheriting is called Hierarchical inheritance.

Hybrid inheritance
This is combination of more than one inheritance. Hence, it may be a combination of Multilevel and Multiple inheritance or Hierarchical and Multilevel inheritance or Hierarchical and Multipath inheritance or Hierarchical, Multilevel and Multiple inheritance.
