Access Modifiers
class MyClass {
public: // Public access specifier
int x; // Public attribute
private: // Private access specifier
int y; // Private attribute
protected: // Protected access specifier
int z; // Protected attribute
};
MyClass myObj;
myObj.x = 25; // Allowed (public)
myObj.y = 50; // Not allowed (private)
myObj.z = 75; // Not allowed (protected)
Comments