Access Specifier/modifier: – It is use to specify the accessibility of data. There are three types of it –
Public: – When the member of class is created inside public section then that member will be called as public member of that class.
- The member inside public section will only be accessed directly from object.
- The member of public section of a class can also be accessed outside that class.
- The member inside public section does not have security.
Private: – The members inside private access specifier are given then the members are called as private members.
The private members cannot be accessed from outside of that class. Private members cannot also be directly accessed by object.
- The private access specifier is used to make the data secured.
- The private members of class will be accessed through public member function of that class.
Protected: – The member inside protected access specifier are said to be protected members.
Just like private access specifier, object cannot access the protected members directly. By using public member function, we can access protected members.
In general case, protected members cannot be access outside the class. But in the case inheritance technique, protected member can be available or be treated as public to its child class.
Note: – Protected also offers data security but not as much as stronger than private.