Dan Chisholm
Posts: 11
Nickname: dchisholm
Registered: Jul, 2002
|
|
Re: static declaration
|
Posted: Aug 3, 2002 9:09 PM
|
|
Any variable declared within a block is a local variable and can not be declared static.
A static field is also called a class variable and there is only one instance of a class variable regardless of the number of instances of the class. In contrast, multiple threads may execute a block of code simultaneously so multiple copies of a local variable may exist at any point in time. For that reason, the definitions of local variables and static variables are not compatible. Of course, only the JVM calls the static initializer, so the multiple thread problem does not exist in that case.
The C programming language allows a local variable to be declared static so that it behaves like a class variable with a scope that is limited to the code block in which it is declared. Java does not provide that feature.
|
|