Inheritence:

The mechanism of deriving a class from another class is known as inheritance.

The class from which another class  is derived is called as the base class.

While the class which is derived is called as derived class.

Assigning a property of class to an object of another class is termed as inheritance.

5types of inheritance

(1)Single Inheritance

(2)Multiple Inheritance

(3)Multilevel Inheritance

(4)Hybrid Inheritance

(5)Hierarchical

  • The protected access specifier restricts access to member functions of the same class, or those of derived classes

hybrid inheritance:

Hybrid inheritance is combination of two or more inheritances such as single,multiple,multilevel or Hierarchical inheritances.
In the below program class B inherits property(member function) of class A which is base class and class D inherits property from class B and class C.

Example:

#include<iostream.h>
#include<conio.h>

class A     //Base class
{
    public:
    int l;
    void len()
    {
        cout<<" Lenght ::: ";   
        cin>>l;                      
    }
};

class B : public A   //Inherits property of class A
{
    public:
    int b,c;
    void l_into_b()   
    {
        len();
        cout<<" Breadth ::: ";
        cin>>b;                      //Breadth is enter by user
        c=b*l;                       //c stores value of lenght * Breadth i.e. (l*b) .   
    }
};

class C
{
    public:
    int h;
    void height()
    {
        cout<<" Height ::: ";
        cin>>h;                      //Height is enter by user
    }
};

//Hybrid Inheritance Level
class D: public B, public C
{
    public:
    int res;
    void result()
    {
        l_into_b();
        height();
        res=h*c;                          //res stores value of c*h  where c=l*b and h is height which is enter by user
        cout<<" Result (l*b*h) ::: "<<res;
    }
};

int main()
{
    clrscr();
    D d1;
    d1.result();
    getch();
}