Answer to Question #186405 in C++ for Ishan

Question #186405

Create two classes named Mammals and MarineAnimals. Create another class named BlueWhale 

which inherits both the above classes. Now, create a function in each of these classes which prints 

"I am mammal", "I am a marine animal" and "I belong to both the categories: Mammals as well as 

Marine Animals" respectively. Now, create an object for each of the above class and try calling

 function of Mammals by the object of Mammal

 function of BlueWhale by the object of BlueWhale

 function of each of its parent by the object of BlueWhale

 function of MarineAnimal by the object of MarineAnimal


1
Expert's answer
2021-04-27T14:54:55-0400
#include <iostream>


using namespace std;


//define class Mammals
class Mammals{
	public:
		void display1() {
			cout << "I am mammal" << endl;
		}
};


//define class MarineAnimals
class MarineAnimals {
	public:
		void display2() {
			cout << "I am a marine animal" << endl;
		}
};


//define class BlueWhale
class BlueWhale : public Mammals, public MarineAnimals {
	public:
		void display3() {
			cout << "I belong to both the categories: Mammals as well as Marine Animals" << endl;
		}
};


int main()
{
	Mammals m;  //object for class Mammals
	MarineAnimals ma; //object for class MarineAnimals
	BlueWhale bw; //object for class BlueWhale
	
	m.display1(); // function of Mammals by the object of Mammal
	ma.display2(); // function of MarineAnimal by the object of MarineAnimal 
	bw.display3(); // function of BlueWhale by the object of BlueWhale 
	bw.display1(); // function of Mammals by object of BlueWhale 
	bw.display2(); // func of MarineAnimals by object of BlueWhale 
	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