+ 1
What is the scope of private, public and protected in c++?
3 ответов
+ 5
Private specifier is used when you want to hide data completely from other classes,
When a variable is declared private it can not be accessed from anywhere except same class functions.
Protected is used when you are using inheritance and want to share variables,
Protected variable can be used from same class as well as inherited child class of that class.
Public means using it anywhere with object.
It can be accessed from any class or any method
+ 1
Private only to the class where it is defined
Protected to the class and its child class
Public every where