Mark As Completed Discussion

Private

Any method, property, or constructor with the private keyword is accessible only from the same class. This is the most restrictive access modifier and is essential to the concept of encapsulation. All data is hidden from the outside world.

You use this access modifier when you don't even want the inherited classes to access this class's property. This modifier can be used to define variables for internal calculations, tracking, and caching that are not needed for any other class to use. For example, we can cache the area of a Rectangle and return it with a getter. No other class needs to know this attribute since they can just use the getter methods.

A general rule of thumb is to keep an attribute as "private" as possible. You'll have fewer weird bugs to deal with later.