C++ Program to add two numbers using function overriding


In this program, You will learn how to add two numbers using function overriding in C++.


class First { public void sum(int,int) { }};

class Second : public First { public void sum(int,int) { }};


Example: How to add two numbers using function overriding in C++

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

class First {
public:

   void add(int x, int y) {
       cout << "Sum in First :" << x + y;
   }
};

class Second : public First {
public:

   void add(int x, int y) {
       cout << "Sum in Second :" << x + y;
   }
};

int main() {

   Second obj;
   obj.add(10, 20);

   return 0;
}

Output:

Sum in Second :30