Encapsulation is the principle of wrapping data inside an object to protect it from unwanted accesses or manipulation. The point of encapsulating the data inside an object is to ensure that the data inside is properly read and written to.
Encapsulation is achieved by setting the data inside a class to private. This makes the fields inaccessible directly from outside the class. Then we define getter and setter methods whose job it is to ensure data is read and written to in a safe and valid way.
Getters
Here is an example showing the usefulness of controlling how data is accessed as well using getter methods:
Because we can have additional checks and improved data integrity by forcing all desired changes to use setter methods. This is ultimately the beauty and point of utilizing encapsulation. You can have more control over your data and ensure that only valid operations are performed with it.