Encapsulation
Encapsulation is the process of wrapping code and data together into a single unit.How to achieve:
private.public setter and getter methods to modify and view the variables values.public class Person {
private String name; // restricted access // Getter
public String getName() {
return name;
}
// Setter
public void setName(String newName) {
this.name = newName;
}
}