Data encapsulation is a fundamental OOPs concept in which data (variables) and code (methods) are wrapped together as a single entity. Because these variables and methods will be hidden from others, they can only be accessible through the current class. Encapsulation protects data from unauthorized changes and can be accomplished in two ways:
Declaring a variable as private in a class
To see and edit the values, use public setter and getter functions.