Answer to Question #180157 in C++ for Aastha

Question #180157

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
2021-04-11T15:53:15-0400
// 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;
}

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