Access Specifier/modifier: – It is use to specify the accessibility of data. There are three types of it –

  1. Public
  2. Private
  3. Protected

Public: – When the member of class is created inside public section then that member will be called as public member of that class.

Syntax: –

                Public:

Note: –

  1. The member inside public section will only be accessed directly from object.
  2. The member of public section of a class can also be accessed outside that class.
  3. 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.

Syntax: –

                Private:

Note: –

  1. The private access specifier is used to make the data secured.
  2. 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.

Syntax: –

                Protected:

Note: – Protected also offers data security but not as much as stronger than private.

Advertisements