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 we try to set the public instance value of class we have to create object of that class and then set the value.and every object refer to different memory.so even if we change the instance value this will not impact to any other object.
Even I try to change using static public instance value also i am not able to change the class property value.
Example is given below
// Employee class
public class Employee {
public static int empid;
public static String empname;
public static void main(String[] args) {
System.out.println("print employe details:"+empid+" "+empname);
}
// EmployeeTest class
public class EmployeeTest {
public static void main(String[] args) {
Employee e = new Employee();
e.empid=20;
e.empname="jerry";
Employee.empid=10;
Employee.empname="tom";
}
}
}
Every time I run Employee
class I am getting same value
print employe details:0 null
Even though I am not following encapsulation concept and I am not able to change public instance value of employee class.Please help me to understand the concept where i am going wrong.