Let see a program, in which base and child class have the same function Display that follows function overriding rule.
// Function Overriding
#include<iostream>
using namespace std;
//Base class
class BaseClass
{
public:
virtual void Display()
{
cout << "In Base class\n";
}
};
//child class
class DerivedClass : public BaseClass
{
public:
// Overriding method - new working of
// base class's display method
void Display()
{
cout << "In Child class\n";
}
};
int main()
{
DerivedClass dr;
BaseClass &bs = dr;
bs.Display();
}
Answer:
Let see a program, in which base and child class have the same function Display that follows function overriding rule.
Output:
In Child class
need an explanation for this answer? contact us directly to get an explanation for this answer