State all the class access modifiers and explain each one of them

 
 

C++ has three access modifiers namely public, private and protected.
Public: a public modifier means that the data or the functions of a class are accessible by any program. There are no restrictions in accessing public members of a class. Ideally all the functions that allow manipulating or accessing the class data are made public.
Private: the private keyword means that the data and member functions that are private cannot be accessed by other programs. They are accessible only within the class or struct in which they are declared. If one tries to access the private members of a class it results in a compile time error. Encapsulation is possible due to the private access modifier.
Protected: this access modifier plays a key role in inheritance. This keyword gives a protected access to the member variables and functions which means that these are accessible from within the class as well as any classes that are derived from the class that declared this member. However the protected members are not accessible to the any other programs.