Q4: 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.
#include<iostream>
using namespace std;
class Base{
public:
void Call() { cout << "Call member function from Base"; }
};
class Derived:public Base{
public:
void Call() { cout << "Call member function from Derived"; }
};
int main()
{
Base b;
cout << "Base Call(): ";
b.Call();
Derived d;
cout << "\nDerived Call(): ";
d.Call();
cout << "\nCall Base Call() from Derived: ";
d.Base::Call();
}
Comments
Leave a comment