C++ Program using function overriding


In this program, You will learn how to implement function overriding in C++.


class First { public void msg() { }};

class Second : public First { public void msg() { }};


Example: How to implement function overriding in C++

Run it Now
#include<iostream>
using namespace std;

class First {
public:

   void msg() {
       cout << "First msg called here ";
   }
};

class Second : public First {
public:

   void msg() {
       cout << "Second msg called here ";
   }
};

int main() {

   Second s = Second();
   s.msg();

   return 0;
}

Output:

Second msg called here