Access Modifier

 Access Specifier

1.It is a keyword which is used to provide accessibility of data member(variable) and member function(function) of a class.
2.It is also called access modifier.

Types of Access Specifier

There are three types of access specifier.

  • Public
  • Private
  • Protected

public
1.It allows the accessibility of data member and member function to the other classes.
2.public element of a class can be accessed anywhere in the program.
private
1.It is used to hide data member and member function from the other classes.
2.private element of a class can be accessed only inside in its own class. 3.private element of a class can not be accessed out of that class.
protected
1.It is approaximately same as private but it allows the accessibility of data member and member function to the child class.
2.protected is used in the case of inheritance.

Post a Comment

0 Comments