+3 votes
in Class 12 by kratos

Describe access specifiers in a class.

1 Answer

+3 votes
by kratos
 
Best answer

The data members and member functions can be accessed using access specifiers. They define the scope of members. The members of class are classified based on private/public/protected members.

1. Private members:
The member data and members functions defined using access specifier private, can be accessed by member functions of that class only. Non-members of . the class cannot access private members of the class. If no access specifier is mentioned for the members, then it is treated as private members.

2. Protected members:
The protected members are similar to private members of a class in a single class. But, if a class is derived from an existing class, then protected members of the base class are accessible to the derived class.

3. Public members:
The public members can be accessed by member functions of the class and non member function (outside the class) of the class. The public member functions can access private, protected and public data members of the class.

...