ENCAPSULATION
ENCAPSULATION
The process of binding the state(attributes/fields) and behaviour of an object together is known as
encapsulation. We can achieve encapsulation in java with the help of the class, class has both state
and behaviour of an object.
DATA HIDING :
● It is a process of restricting the direct access of data members of an object and provides indirect
secured access of data members via methods of the same object is known as data hiding.
● Data hiding helps to verify and validate the data before storing and modifying
it.
STEP 1: Prefix data members of a class with the private modifier. [ ● private is an access modifier. If
the members of the class are prefixed with a private modifier then we can access that member only
within the class.]
GETTER METHOD :
● The return type of the getter method is the type of the hidden value.
SETTER METHOD :
ADVANTAGES :
➔ Only readable
➔ Only modifiable