Access specifier in c++

An access specifier offers the means by which it is possible to define how the class members, i.e. functions and variables, will be accessed outside the scope of the class.

There are three types of access specifier are in c++:

  • private – Such class members can’t be accessed outside the class in which they are declared and are only accessible within the same class. Even child classes are disabled to access private members of its parent class
  • Protected – In addition to the class in which they are declared, the child classes can access the protected members of its parent class
  • Public – Class members declared as public can be accessed throughout the program (code)
Posted on by