Java Encapsulation Concept not clear

后端 未结 12 2379
死守一世寂寞
死守一世寂寞 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 03:56

    encapsulation =VARIABLES(let private a,b,c)+ METHODS(setA&getA,setB&getB....) we can encapsulate by using the private modifier. let consider your created one public variable and one private variable in your class... in case if you have to give those variables to another class for read-only(only they can see and use not able to modify) there is no possibility with public variables or methods,but we can able to do that in private by providing get method. so Your class private variables or methods are under your control. but IN public there is no chance....i think you can understood.

提交回复
热议问题