Encapsulation is a mechanism to protect private hidden from other users. It wraps the data and methods as a single bundle. private is the keyword used to declare the variables or methods as private. You can make public set and get methods to access private variables.
The get method returns the value of the variable name.
The set method takes a parameter (newName) and assigns it to the name variable. The this keyword is used to refer to the current object.