Encapsulation in Java with example:
For Video : CLICK HERE
Encapsulation is also known as Data hiding.
If a class have private member & it is required to access these private member from outside of class then we have to create public getter & setter method.
This way data can only be accessed by public methods thus making the private fields and their implementation hidden for outside classes.
private string Name;
private Int Age;
public string getName()
public void setName(String Name)
this.Name = Name;
public int getAge()
public void setAge(int Age)
this.Age = Age;
public class Chandan1
public static void main(String args)
chandan obj = new chandan();
System.out.println("Your name is :" +obj.getName);
System.out.println("Your Age is :" +obj.getAge);
Your name is :Chandan
Your Age is :25