Access Specifiers
Access Specifiers
• Access modifiers or Access Specifiers in a class are used to set the accessibility of
the class members. That is, it sets some restrictions on the class members not to
get directly accessed by the outside functions.
1. Private
2. Protected
3. Public
Note: If we do not specify any access modifiers for the members inside the class then
by default the access modifier for the members will be Private.
Private
• By private we mean that members can be accessed only from within the
class i.e member data can be accessed by the member function.
• The private data members are not accessible to the outside world (i.e
outside the class)
• Only the member functions or the friend functions are allowed to access
the private data members of a class.
Protected
int rollno;
float marks;
public:
void getdata();
void display();
};