0% found this document useful (0 votes)
8 views1 page

ENCAPSULATION

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

ENCAPSULATION

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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.

By using encapsulation we can achieve data hiding.

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.

STEPS TO ACHIEVE DATA HIDING :

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.]

STEP 2: Design a getter and setter method.

GETTER METHOD :

● The getter method is used to fetch the data.

● The return type of the getter method is the type of the hidden value.

SETTER METHOD :

● The setter method is used to update or modify the data.

● The return type of the setter method is always void.

ADVANTAGES :

● Provides security to the data members.

● We can verify and validate the data before modifying it.

● We can make the data member of the class to

➔ Only readable

➔ Only modifiable

➔ Both readable and modifiable

➔ Neither readable and modifiable

You might also like