Saturday, September 24, 2016

Multilevel Inheritance

Multilevel:

It is a type of inheritance in which the derived class is used as base class to derive another class.
Thus the second derived class has features of both base and 1 st derived class.

 Program to Illustrate The Multilevel Inheritance:


#include<iostream>
using namespace std;
class base
{
    int a;
    protected:
        int b;
    public:
        int c;
        void getdata();
        void display();
};
void base:: getdata()
{
    cout<<"Enter The Values Of A,B,C\n";
    cin>>a>>b>>c;
}
void base::display()
{
    cout<<"Values Are\n";
    cout<<"A="<<a;
    cout<<"\nB="<<b;
    cout<<"\nC="<<c;
}
class derive:public base
{
    int d;
    protected:
        int e;
    public:
    void displaay()
    {
        cout<<"\nD="<<d;
        cout<<"\nE="<<e;
    }
            void input()
            {
                cout<<"\nEnter D AND E\n";
                cin>>d>>e;
       
            }
};
class derive1:public derive
{
    int f;
    protected:
        int g;
    public:
        void getfg()
        { cout<<"Enter F And G\n";
            cin>>f>>g;
        }
        void putfg()
        {
        cout<<"\nF="<<f;
        cout<<"\nG="<<g;
        }
};

main()
{
    derive1 p;
    p.getdata();
    p.input();
    p.getfg();
    p.display();
    p.displaay();
    p.putfg();
}