Header Ad

C++ program to inherit the class

In this post, we will write a C++ program to inherit the class.

C++ program to inherit the class


C++ program to inherit the class.

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

class base
{
    public:
        void display()
        {
            std::cout<<"It is base class";
        }
};

class derived:public base
{
    public:
        void dis()
        {
            std::cout<<"\nIt is a derived class";
        }
};

int main()
{
    system("cls");

    derived d;
    d.display();
    d.dis();

    getch();
    return 0;
}



Output

It is base class
It is a derived class

Post a Comment

0 Comments