C++ Programming

Program to Implement Multilevel Inheritance C++

Write a Program to Implement Multilevel Inheritance.

  1. Single Inheritance
  2. Multiple Inheritance
  3. Hierarchical Inheritance

Source Code

#include<iostream>

#include<conio.h>

using namespace std;

class data

        {

            protected:

            int count;

        };

class increment:public data

        {

            public:

            increment()

        {

            count=1;

        }

void operator ++()

        {

            count++;

            cout<<"After Incrementing: "<<count<<endl;

        }

    };

class decrement:public increment

        {

            public:

            decrement()

        {

                count=1;

        }

void operator --()

    {

            count--;

            cout<<"After Decrementing: "<<count<<endl;

    }

};

int main()

{

        decrement a;

        increment b;

        cout<<"Initially count=1"<<endl;

        ++b;

        --a;

}

Output

Multilevel Inheritance

Back to top button