Java Encapsulation Concept not clear

后端 未结 12 2405
死守一世寂寞
死守一世寂寞 2020-11-30 03:40

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

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 04:03

    The reason you are getting the output "print employe details:0 null" when running the Employee class is because those variables are not initialized. That is, you do not assign any values to them within the Employee class.

    Whatever you do within the EmployeeTest class will not affect the values of the variables in Employee the next time it is run. Consider each run of a Java program a "clean slate".

    On the point of encapsulation, you really should not be using the static keyword. If you are going for encapsulation check out the other answer to this question, it has a nice code sample for you to use.

提交回复
热议问题