Access Specifier In C++

Access specifier

A key feature of object oriented programming is data hiding. It means that data is hidden. So that it can’t be accessed mistakenly by functions outside the class. The class feature of C++ implements the concept of encapsulation by providing access specifier.
Access specifier is the keyword used for defining the scope of the member of class. There are three access specifier in c++.

  • Private
  • Public
  • Protected

These three access specifier are used to specify the three levels of access protections for hiding data and function members.


The private data and function can be accessed from within the class. I.e. only from member of the same class. They are not accessible to the outside world. Hence, the primary mechanism for hiding data is to put data and function in a class and make them private.


Public members of a class are accessible from within or outside the class i.e. they can be accessed by any unction inside or outside the class. These public members are accessible from derived class and also from object outside the class.


The protected data and functions can be accessed by the member functions of the same class. Also, these functions can be accessed by the member function of the derived class. But, it is not accessible to the outside world.

Related posts:

  1. Class In C++ Class in c++ Class is a group of similar object....
  2. Array Of Class Object Array of class objects Array is a collection of similar...
  3. Defining Member Function In C++ Class methods definitions  (Defining the member functions) Member functions can...
  4. Object oriented programming Object oriented programming : The main idea behind object oriented...
  5. Destructor In C++ Destructor in c++ It is used o destroy the object...