In this post, we will write a C++ program to override a function.
C++ program to override a function.
#include<iostream>
#include<conio.h>
class base
{
public:
void fun()
{
std::cout<<"World is great";
std::cout<<"nIt is a base class";
}
};
class derived : public base
{
public:
void fun()
{
std::cout<<"nHigher Education"<<std::endl;
std::cout<<"It is a derived class";
}
};
int main()
{
system("cls");
derived d;
d.fun();
getch();
return 0;
}
Output
Higher Education It is a derived class