Sunday, 3 April 2016

Explain Inheritance and its types in c++





Inheritance:- 
                                                 Inheritance means using the Pre-defined Code This is very Main Feature of OOP With the advantage of Inheritance we can use any code that is previously created. With the help of inheritance we uses the code that is previously defined but always Remember, We are only using that code but not changing that code. 

                                                With the Advent of inheritance we are able to use pre-defined code and also able to add new code. All the pre-defined code is reside into the form of classes if we want to use that code then we have to inherit or extend that class.
 
                                                    The Class that is Pre-defined is called as Base or super Class and the class which uses the Existing Code is known as derived or sub class 

Types of Inheritance

In C++, we have 5 different types of Inheritance. Namely,
  1. Single Inheritance
  2. Multiple Inheritance
  3. Hierarchical Inheritance
  4. Multilevel Inheritance
  5. Hybrid Inheritance (also known as Virtual Inheritance)

Single Inheritance

In this type of inheritance one derived class inherits from only one base class. It is the most simplest form of Inheritance.
Single Inheritance in C++

Multiple Inheritance

In this type of inheritance a single derived class may inherit from two or more than two base classes.
Multiple Inheritance in C++

Hierarchical Inheritance

In this type of inheritance, multiple derived classes inherits from a single base class.
Hierarchical Inheritance in C++

Multilevel Inheritance

In this type of inheritance the derived class inherits from a class, which in turn inherits from some other class. The Super class for one, is sub class for the other.
Multilevel Inheritance in C++

Hybrid (Virtual) Inheritance

Hybrid Inheritance is combination of Hierarchical and Mutilevel Inheritance.
Hybrid Inheritance in C++


No comments:

Post a Comment