Skip to content

Commit 4bc71b7

Browse files
Added the code for Single Inheritance in C++
1 parent b738747 commit 4bc71b7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// C++ program to demonstrate Single Inheritance
2+
3+
// Single Inheritance - It is defined as the inheritance in which a derived class is inherited
4+
// from a single base class.
5+
6+
#include<bits/stdc++.h>
7+
using namespace std;
8+
9+
// base class
10+
class Animal{
11+
public:
12+
void eat(){
13+
cout<<"I can eat!"<<endl;
14+
}
15+
void sleep(){
16+
cout<<"I can sleep!"<<endl;
17+
}
18+
};
19+
20+
// derived class
21+
class Cat:public Animal{
22+
public:
23+
void meow(){
24+
cout<<"I can meow! meow! meow!"<<endl;
25+
}
26+
};
27+
28+
int main(){
29+
// Create object of the Cat class
30+
Cat cat1;
31+
// Calling members of the base class
32+
cat1.eat();
33+
cat1.sleep();
34+
// Calling member of the derived class
35+
cat1.meow();
36+
return 0;
37+
}

0 commit comments

Comments
 (0)