We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Not Security

Encapsulation is all about making code easy to work with by "hiding" complicated code within a "black box". It makes it so we don't have to worry about the details of how a function or method works... we just use it.

This is kinda like how the inner workings of your car's power steering are hidden from you. You don't need to be an expert on hydraulic systems to turn the wheel from side to side.

Let me say this next part loud and clear:

Encapsulation and the concepts of private and public members have NOTHING to do with security. This really confused me as a new developer. Just as the casing on your computer hides its inner workings but doesn't stop you from opening the case and looking inside, encapsulation doesn't stop anyone from knowing how your code works; it just puts it all in one easy-to-find place.

Encapsulation is about organization, not security.

Making a property "private" tells other developers that it's an internal detail of your class. It doesn't make the value stored in that property secret.