Multi Level Inheritance With Example and Program

Explain Multi Level Inheritance With Example and Program





Multi level inheritance: -
The mechanism of deriving a new class from existing derived class is called multi level inheritance”. The object of the derived class is having a capability to access base class and intermediate base class data members and member functions.

# include<iostream.h>
            class student
            {
            protected :
                        int rno ;
                          char name[20];
             public:
                        void get()
                        {cout <<"enter roll no. and name";
                           cin>>rno>>name;
                        }
                        void show ()
                        {
                        cout<<"Roll number:"<<rno<<”Name:”<<name<<endl;
                        }
            };
            class test : public student
            {
            protected :int m1, m2;
            public : void getmarks  ( )
            {
            cout<<"enter marks in 2 subjects";
            cin>>m1>>m2;
                void showmarks ( )
            {
            cout<< "subject1:"<<m1;
            cout<<"subject 2:"<<m2;
            }
            };
            class final : public test
            {
            private : float total;
            public: void display ()
            {
            total= m1+m2;
            show( );
            showmarks ( ) ;
            cout<<"Total:"<<total;
            }
};
            void main ( )
            {  final f
               f.get( );
               f.getmarks ( );
               f.display ( );
            }

Labels: