What do you mean by C++ access specifiers ?
[Questions regarding access specifiers are common not just in c++ interview but for other object oriented language interviews as well.]
Access specifiers are used to define how the members (functions and variables) can be accessed outside the class. There are three access specifiers defined which are public, private, and protected
- private:
Members declared as private are accessible only with in the same class and they cannot be accessed outside the class they are declared. - public:
Members declared as public are accessible from any where. - protected:
Members declared as protected can not be accessed from outside the class except a child class. This access specifier has significance in the context of inheritance.
No comments:
Post a Comment