Encapsulation in a nutshell is “hiding the data“. It restricts direct access to data of an object.
Encapsulation can be applied to data members or methods.
It is done by putting the “private” keyword before the class property name or method name.
Private – A member is private and accessible to only members of the class but not outside the class.
Public – Accessible anywhere by other objects or users.
A well encapsulated class would be in which data members are only accessible through its methods/functions only.
Learn more in this video: