C++ Private Access Specifiers

C++ Private Access Specifiers


C++ Private Access Specifier:
  • The private access specifier is used to restrict the use of class member within the class.
  • Any member of the class declared with public access from anywhere in the program.
  • It can’t be accessed from outside the class.
  • It is also the default access specifier.
  • The data members are normally declared with a private access specifier.
  • It is because the data of an object is more sensitive.
  • The private access specifier is to protect the data member from direct access from outside the class.
  • These data members can only be used by the functions declared within the class.
Example
Output
https://lh3.googleusercontent.com/HeplZwHg3DCNS4mgg99m-WKng1YOvuUrxXlb05U_YhEgV4pwIuhvSwAAlv1OA-UZ_9VRqd8ZElAcgKh7UdkqxaLix3KX3vPpZ-gw6xpKGRdnFmiQWA2KXaKAQ7wo0v9J7hGO160a