Encapsulation is the three major features of object-oriented programming. encapsulation is to combine the member attributes and member methods of an object into an independent and identical unit, and try to hide the internal details of the object, form a boundary, and retain only a limited number of external interfaces to associate them with the external. The encapsulation of member attributes or member methods is achieved by adding the keyword private before it. Class Members modified by private cannot be accessed externally, but members inside the object can access the encapsulated members inside the object, the encapsulation of object members is one of the three main features of object-oriented programming. encapsulation is to combine the member attributes and member methods of an object into an independent and identical unit, it tries its best to conceal the internal details of the object, form a boundary, and retain only a limited number of external interfaces to associate them with the external.
Encapsulation Implementation Method
The encapsulation of member attributes or member methods is achieved by adding the keyword private before it. Class Members modified by private cannot be accessed externally, but members inside the object can access the encapsulated members inside the object to protect the members of the object.
We use private to encapsulate members in the Person class: