What is encapsulation in java.

encapsulation :- It is a process of wrapping the variable and methods in a single unit is called encapsulation.

  • We will be declare of variable with private access modifier.
  • The variable of a class will be hidden from other class and can be access only from the method of their current class.
  • A class can be change the data type of class but user of the class don’t need to change any of their code.
  • Here we bind the data from setter() and getter() method. method.
  • The field of a class can be make read only or write only.
					class Employee {
	private String name;
	public String getName() {
		return name;
	public void setName(String name) {
		this.name = name;
public class TestEncapsulate {
	public static void main(String[] args) {
		Employee emp = new Employee();
		System.out.println("Employee name is--" + emp.getName());

Output :- 
Employee name is–dinesh