Java setting private fields inside constructors

前端 未结 10 745
独厮守ぢ
独厮守ぢ 2021-01-17 15:48

Common design practice is to make instance variables private and have public getters and setters to access them. But many times I have seen code samples on the internet that

10条回答
  •  無奈伤痛
    2021-01-17 16:00

    the private variables are accessible directly anywhere in the class

    settng variabels private is to encapsulate them from other classes

提交回复
热议问题