Encapsulation
public class EncapTest {
/* Encapsulation is a concept that binds together the data and functions that manipulate the data,
and that keeps both safe from outside interference and misuse. */
private String name;
private String idNum;
private int age;
public int getAge() {
return age;
}
public String getName() {
return name;
}
public String getIdNum() {
return idNum;
}
public void setAge(int newAge) {
age = newAge;
}
public void setName(String newName) {
name = newName;
}
public void setIdNum(String newId) {
idNum = newId;
}
public static void main(String[] args) {
EncapTest test = new EncapTest();
test.setIdNum("10");
test.setAge(25);
test.setName("smith");
System.out.println(test.getIdNum());
System.out.println(test.getAge());
System.out.println(test.name);
}
}
Output:
10
25
smith