What is function overriding in C++ ?

When a function with same name is present in both parent and child class then it is called function overriding.

#include <iostream>
using namespace std;
class parent {
public:
   void display(){
      cout<<"Parent Class";
   }
};
class child: public parent{
public:
   void display() {
      cout<<"Child Class";
   }
};
int main() {
   child o = parent();
   o.display();
   return 0;
}

Leave a Comment