File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change 1
- // C++ program to demonstrate Protected Inheritance
1
+ // C++ program to demonstrate Private Inheritance
2
2
3
- // Protected Inheritance - It is defined as the inheritance in which public members of the base class becomes protected members
4
- // of the derived class and also the protected members of the base class becomes protected members of the derived class.
3
+ // Private Inheritance - It is defined as the inheritance in which public members of the base class becomes private members
4
+ // of the derived class and also the protected members of the base class becomes private members of the derived class.
5
5
6
6
// Note : Private members are not inherited.
7
7
@@ -25,7 +25,7 @@ class Animal{
25
25
};
26
26
27
27
// derived class
28
- class Cat :protected Animal {
28
+ class Cat :private Animal {
29
29
public:
30
30
void animal_info (){
31
31
sleep ();
@@ -39,8 +39,7 @@ class Cat:protected Animal{
39
39
int main (){
40
40
// Create object of the Cat class
41
41
Cat cat1;
42
- // Calling public and protected members of the base class through derived class function
43
- // Note : Only derived class can access the member functions and data members of the base class in case of protected inheritance.
42
+ // Calling public and protected members of the base class through derived class function (because they are private members in derived class)
44
43
cat1.animal_info ();
45
44
// Calling member of the derived class
46
45
cat1.meow ();
You can’t perform that action at this time.
0 commit comments