Answer to Question #327127 in C++ for Zanies

Question #327127

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.


1
Expert's answer
2022-04-12T16:16:07-0400
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS