Do we have a Readonly field in java (which is set-able within the scope of the class itself)?

前端 未结 7 1065
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 01:31

How can we have a variable that is writable within the class but only \"readable\" outside it?

For example, instead of having to do this:

Class          


        
7条回答
  •  既然无缘
    2021-02-01 02:14

    there is no way to make a field "read only" from outside. the only - and right - way is to make the fields private and provide only getters, no setters.

提交回复
热议问题