Answer to Question #231995 in C++ for mahnoor

Question #231995

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

1.  function of Mammals by the object of Mammal

2. function of MarineAnimal by the object of MarineAnimal

3. function of BlueWhale by the object of BlueWhale

4. function of each of its parent by the object of BlueWhale

 


1
Expert's answer
2021-09-03T15:18:08-0400
#include <iostream>
using namespace std;
class Mammals{
	public:
		void print1() {
			cout << "\nI am mammal";
		}
};
class MarineAnimals {
	public:
		void print2() {
			cout << "\nI am a marine animal";
		}
};


class BlueWhale : public Mammals, public MarineAnimals {
	public:
		void print3() {
			cout << "\nI belong to both the categories: Mammals as well as Marine Animals";
		}
};




int main()
{
	Mammals m; 
	MarineAnimals ma; 
	BlueWhale bw; 
	
	m.print1(); 
	ma.print2();  
	bw.print3(); 
	bw.print1();  
	bw.print2(); 
	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