Skip to content

Commit b11ce05

Browse files
authored
Merge pull request #643 from pushpakumari5117/issue-329
Added the code for Private Inheritance in C++
2 parents 0347301 + 979f234 commit b11ce05

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

OOPs/Inheritance/Protected_Inheritance_cpp.cpp renamed to OOPs/Inheritance/Private_Inheritance_cpp.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// C++ program to demonstrate Protected Inheritance
1+
// C++ program to demonstrate Private Inheritance
22

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.
55

66
//Note : Private members are not inherited.
77

@@ -25,7 +25,7 @@ class Animal{
2525
};
2626

2727
// derived class
28-
class Cat:protected Animal{
28+
class Cat:private Animal{
2929
public:
3030
void animal_info(){
3131
sleep();
@@ -39,8 +39,7 @@ class Cat:protected Animal{
3939
int main(){
4040
// Create object of the Cat class
4141
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)
4443
cat1.animal_info();
4544
// Calling member of the derived class
4645
cat1.meow();

0 commit comments

Comments
 (0)