This is basic question but still i don\'t understand encapsulation concept . I did\'t understand how can we change the properties of class from other class.because whenever
public static field's are associated with class not with object, it break Object's encapsulation rule.
Employee class with two encapsulated field empid & empname.
public class Employee {
private int empid;
private String empname;
public int getEmpid(){
return this.empid;
}
public void setEmpid(int empid){
this.empid = empid;
}
...
}
public class EmployeeTest {
public static void main(String[] args) {
Employee e = new Employee();
e.setempId(1);
Employee e1 = new Employee();
e1.setempId(2);
}
}
Documentation for better understanding on encapsulation