Encapsulation

Encapsulation is the mechanism of binding the private variable and public method in a single unit is called as encapsulation.

Encapsulation is one of the most important concept of object oriented programming language.

Main purpose of encapsulation is to provide security to data by declaring the variable as private.

Through encapsulation we can achieve data security means that any unauthorized user does not access the data and it can show only required data to the user.

How we can achieve encapsulation

By declaring our data member with private access modifier and by declaring public method like getter and setter for retrieving those private variable by doing this to steps we can achieve Encapsulation in java.