[请求] static private variables in Java

陨石

知名会员
VIP
注册
2003-03-18
消息
994
荣誉分数
33
声望点数
158
What is the benefit to declare a private variable with static if this variable will only be referenced by non-static methods?

Thanks
 
Static variable is a global variable for
all instances of a class. If you have
a private static variable and change it
in one instance, all other instance will
know the change too.
 
Ok, good point. Thanks.
If we add a "final" keyword on it, so no change will be allowed on private static final variable,
is there still any benefit to do so?
Thanks.
 
后退
顶部