This presentation on the C++ Inheritance tutorial will help you learn about Inheritance in C++ and why we use inheritance in C++. You will also understand modes of inheritance and different types of inheritance in C++. You will get an introduction to inheritance in C++ programming with examples of the different types of inheritance.
Below topics are covered in this presentation:
1. What is inheritance?
2. Why do we use inheritance?
3. Modes of inheritance
4. Types of inheritance
5. Single inheritance
6. Multiple inheritances
7. Multilevel inheritance
8. Hierarchical inheritance
9. Hybrid inheritance
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming With Example | Simplilearn
1.
2. Multiple inheritance
What is Inheritance ?
Why do we use inheritance in C++?
Types of inheritance
Single inheritance
Modes of inheritance
Multi-level inheritance
Heirarchical inheritance
Hybrid inheritance
What’s in it for you ?
3. What is inheritance ?
Inheritance can be defined as a process in which objects of child
class acquires properties and characteristics from the parent
class.
In C++, OOPs concept inheritance is one of the most important
feature.
The class which inherits the properties is called the derived
class, and the class whose properties or characteristics are
inherited is called the base class.
Inherited
properties
5. Why do we use inheritance ?
Inheritance is used because it helps in removing data
redundancy and increases the reusability of code.
To understand it, let’s suppose there are two classes two
wheeler and four wheeler both of the classes contains
similar functions like color() , brand(), Mileage().
Four wheeler Two wheeler
Color()
Brand()
Mileage()
Color()
Brand()
Mileage()
6. Why do we use inheritance ?
With Inheritance, we inherit both the classes from
one base class, i.e. class vehicle..
Now we have to write functions only once as both
the classes are now inherited from the base class.
Four wheeler
Color()
Brand()
Mileage()
Two wheeler
Color()
Brand()
Mileage()
Class vehicle
Color()
Brand()
Mileage()
Base class
7. Modes of inheritance
There are three modes of inheritance i.e Public, protected and
private.
Public mode: In this mode of inheritance the public members of the
base class remain public in the derived class, and same goes for
protected members.
Protected mode: In this mode the public and protected members of
the base class will become protected in the derived class.
Private mode: In Private mode protected and public members of
class will become private in the derived class.
8. Types of inheritance
There are various types of inheritance in C++ :
• Single inheritance
• Multiple inheritance
• Multi-level inheritance
• Heirarchical inheritance
• Hybrid inheritance
9. Single inheritance
In this type of inheritance, there is a single derived class
from a single base class.
Syntax:
Class derived_class : access_modifier Base_class
{
//body
};
Class Base_class
Class derived_class
10. Multiple inheritance
In this type of inheritance, the derived class is inherited from
more than one base class.
Syntax:
Class derived_class : access_modifier Base_class1 ,
access_modifier Base_class2
{
//body
};
Class
Base_class1
Class
derived_class
Class
Base_class2
11. Multi-level inheritance
In Multi-level inheritance, the derived class is inherited
from another derived class.
Syntax:
Class Base_class2 : access_modifier Base_class1
{
//body
};
Class derived_class : access_modifier Base_class2
{
//body
};
Class
Base_class1
Class
derived_class
Class
Base_class2
12. Heirarchical inheritance
If more than one class is inherited from the base class
then it is known as hierarchical inheritance.
Syntax:
Class derived_class1 : access_modifier Base_class
{
//body
};
Class derived_class2 : access_modifier Base_class
{
//body
};
Class derived_class3 : access_modifier Base_class
{
//body
};
Class
Base_class
Class
derived1
Class
derived2
Class
derived3
13. Hybrid inheritance
Hybrid inheritance is implemented by combining
more than one type of inheritance.
It can be said as the combination of both multilevel
and hierarchical inheritance.
Class
Base_class1
Class
derived_class2
Class
derived_class1
Class
derived_class3