Access specifiers - C++ Class

How are access specifiers used in C++ classes?

Explanation

Access specifiers defines the access rights for the statements or functions that follows it until another access specifier or till the end of a class. The three types of access specifiers are "private", "public", "protected".

private:


The members declared as "private" can be accessed only within the same class and not from outside the class.

public:


The members declared as "public" are accessible within the class as well as from outside the class.

protected:


The members declared as "protected" cannot be accessed from outside the class, but can be accessed from a derived class. This is used when inheritaance is applied to the members of a class.


The members declared as "public" are accessible within the class as well as from outside the class.

C++ Tutorial


Ask Questions

Ask Question