Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

EXPERIMENT NO – 4

SAKSHI V.TAWDE
ROLL NO – 62
SEIT2 I6batch

AIM – Implement inheritance in C++ .Create two classes named Mammals and
MarineAnimals.
INPUTS – Create classes and print “I am mammal”, “I am a marine animal” ,
and “ I belong to both the categories: Mammals as well as Marine Animals”.
PROCESS -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" . Now, create an object for each of the above class and try
calling.
THEORY – We need to implement the program using inheritance in
c++.Inheritance is capability of a class to derive properties and characteristics
from another class.
PROGRAM -
#include <iostream>
using namespace std;
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;
MarineAnimals ma;
BlueWhale bw;
m.display1();
ma.display2();
bw.display3();
bw.display1();
bw.display2();
return 0;
}
OUTPUT –
LEARNING OUTCOME – By using method of inheritance we can obtain the
required output.
CONCLUSION – We have obtained the output in c++.

You might also like