- 论坛徽章:
- 1
|
本帖最后由 laolun 于 2014-01-22 17:02 编辑
另外附上我认为比较靠谱的其他解答:
解答1
Because the static variables are allocated memory at the class loading time,and the memory is allocated only once.Now if you have a static variable inside a method,then that variable comes under the method's scope,not class's scope,and JVM is unable to allocate memory to it,because a method is called by the help of class's object,and that is at runtime,not at class loading time.
解答2
Static variables belong to the class; variables declared inside a method are local variables and belong to that method. So you can call them final, but not static or public or protected or private.
|
|