the use of private keyword

后端 未结 12 1743
栀梦
栀梦 2021-01-01 14:00

I am new to programming. I am learning Java now, there is something I am not really sure, that the use of private. Why programmer set the variable as private then write , ge

12条回答
  •  悲&欢浪女
    2021-01-01 14:46

    C# programmers use this equally as much, or maybe more frequently than I see in Java. C# calls it properties where in Java it is accessors/mutators

    For me it makes sense to have getter and setter methods to encapsulate the classes so that no class can change the instance variables of another class.

提交回复
热议问题