what are access specifiers in c 2b 2b

Solutions on MaxInterview for what are access specifiers in c 2b 2b by the best coders in the world

showing results for - "what are access specifiers in c 2b 2b"
Francesco
29 Aug 2016
1class MyClass {  // The class
2  public:        // Access specifier
3    // class members goes here
4};
5
6The public keyword is an access specifier. 
7Access specifiers define how the members (attributes and methods) of a 
8class can be accessed. 
9In the example above, the members are public - which means that they 
10can be accessed and modified from outside the code.
11
12However,
13 what if we want members to be private and hidden from the outside world?
14
15In C++, there are three access specifiers:
16
17public - members are accessible from outside the class
18private - members cannot be accessed (or viewed) from outside the class
19protected - members cannot be accessed from outside the class, 
20however, they can be accessed in inherited classes.
21