File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments