Suppose, the same function is defined in both the derived class and the based class. Now if we call this function using the object of the derived class. Compiler will call which function and elaborate the same used by the compiler
// In the inherited class, the function will replace the function of the base class.
#include <iostream>
using namespace std;
class Base
{
public:
void Display() { cout << "In Base!" << endl; }
};
class Derived : public Base
{
public:
void Display() { cout << "In Derived!" << endl; }
};
int main()
{
Base base;
base.Display();
Derived derived;
derived.Display();
cout << endl;
return 0;
}
Comments
Leave a comment