ExamVeda
Login
Home
Inheritance in C plus plus
?

What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
 
class Mammal
{
   public:
	virtual void Define(){
		cout<<"I'm a Mammal\n";
	}
};
 
class Human: public Mammal
{
   public:
	void Define(){
		cout<<"I'm a Human\n";
	}
};
 
class Male: public Human
{
   public:
	void Define(){
		cout<<"I'm a Male\n";
	}
};
 
class Female: public Human
{
   public:
	void Define(){
		cout<<"I'm a Female\n";
	}
};
 
int main(int argc, char const *argv[])
{
	Mammal *M = new Mammal();
	Male m;
	Female f;
	*M = m;
	M->Define();
	M = &m;
	M->Define();
	return 0;
}

Answer & Solution
Correct Answer: Option C
Let's discuss the solution. Join the discussion
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.