Example & Tutorial understanding programming in easy ways.

What is multiple inheritance in C++?

What is Inheritance in C++ :
In C++,
-Inheritance is a process in which one object acquires all the properties and behaviors of its parent object automatically. In such way, you can reuse, extend or modify the attributes and behaviors which are defined in other class.

Syntax for Inheritance:
class parent
{
};
class child: public parent
{
};
-Here child class acquire the properties of parent child.

Type of Inheritance in C++:
-Single Inheritance
-Multiple Inheritance
-Multilevel Inheritance
-Hierarchical inheritance
-Hybrid inheritance

1.Single Inheritance:
-When a parent have only one child then it is called single Inheritance.
Syntax-
class parent
{
};
class child: public parent
{
};

2.Multiple Inheritance:
-When child class inherite the property from multiple class then it is called Multiple Inheritance.
Syntax-
class one
{
};
class two
{
};
class three
{
};
class child:public one,public two, public three
{
};

3.Multi-level Inheritance:
-When child class work as parent for another third class then it is called as Multi-level Inheritance.
Syntax-
class one
{
};
class two:public one
{
};
class three:public two
{
};

4.Hierarchical inheritance
-Hierarchical inheritance is defined as the process of deriving more than one class from a base class.
syntax:
class parent
{
};
class child1 : public parent
{
};
class child2 : public parent
{
}

5.Hybrid Inheritance:
-It is any combination of above another inheritance.




Read More →