Answers for "what is access specifier in c++ with example"

C++
1

what are access specifiers in c++

class MyClass {  // The class
  public:        // Access specifier
    // class members goes here
};

The public keyword is an access specifier. 
Access specifiers define how the members (attributes and methods) of a 
class can be accessed. 
In the example above, the members are public - which means that they 
can be accessed and modified from outside the code.

However,
 what if we want members to be private and hidden from the outside world?

In C++, there are three access specifiers:

public - members are accessible from outside the class
private - members cannot be accessed (or viewed) from outside the class
protected - members cannot be accessed from outside the class, 
however, they can be accessed in inherited classes.
Posted by: Guest on May-14-2021

Code answers related to "what is access specifier in c++ with example"

Browse Popular Code Answers by Language