An overview on class access specifiers
When using an object-oriented programming language, one of the most important features included is the ability to hide data, preventing classes from accessing properties and functions of another class type by default. By using access specifiers such as public
, private
, and protected
, we can dictate specifically how the data and/or functions can be accessed from other classes:
class ModifierExamples { public int publicInteger; private void PrivateMethod() {} protected float protectedNumber; };
A class can have unlimited variables or functions that are public
, private
, or protected
and can even control access to entire sections of the class:
class MoreModifierExamples { public: // until we reach another tag, all variables and functions // will be public int publicIntegar; int anotherExample; private: // Now, they'll be private void PrivateFunction() {} double safeValue; protected: // And now...