C++ Programming

Program to Implement Hierarchical Inheritance C++

Write a Program to Implement Hierarchical Inheritance.

  1. Single Inheritance
  2. Multiple Inheritance
  3. Multilevel 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 data

    {

    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;

        return 0;

    }

Output

Hierarchical Inheritance

Back to top button