![]() |
VOOZH | about |
Protected access modifier is similar to that of private access modifiers, the difference is that the class member declared as Protected are inaccessible outside the class but they can be accessed by any subclass(derived class) of that class.
Example:
id_protected is: 81
The class members declared as private can be accessed only by the functions inside the class. They are not allowed to be accessed directly by any object or function outside the class. Only the member functions or the friend functions are allowed to access the private data members of a class.
Example:
Radius is: 1.5 Area is: 7.065
| Private | Protected |
|---|---|
| The class members declared as private can be accessed only by the functions inside the class. | Protected access modifier is similar to that of private access modifiers. |
| Private members keep implementation details in a program. | Protected members enhanced access for derived classes. |
| Only the member functions or the friend functions are allowed to access the private data members of a class. | The class member declared as Protected are inaccessible outside the class but they can be accessed by any subclass(derived class) of that class. |
| Private members are inherited by derived classes but are not directly accessible in the derived classes.. | Protected member are inherited in class. |