-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_18.cpp
More file actions
46 lines (39 loc) · 992 Bytes
/
Problem_18.cpp
File metadata and controls
46 lines (39 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;
// Base Class
class Animal {
public:
void displayAnimal() {
cout << "I am an Animal." << endl;
}
};
// Derived Class 1 (Single Inheritance from Animal)
class Mammals : public Animal {
public:
void displayMammals() {
cout << "I am a Mammal." << endl;
}
};
// Derived Class 2 (Independent Class)
class Herbivores {
public:
void displayHerbivores() {
cout << "I am a Herbivore." << endl;
}
};
// Derived Class 3 (Multiple Inheritance from Mammals and Herbivores)
class Cow : public Mammals, public Herbivores {
public:
void displayCow() {
cout << "I am a Cow, a Mammal and a Herbivore." << endl;
}
};
int main() {
Cow cow;
// Calling methods from different classes
cow.displayAnimal(); // From Animal
cow.displayMammals(); // From Mammals
cow.displayHerbivores(); // From Herbivores
cow.displayCow(); // From Cow
return 0;
}