|
Re: Use of Static Variables
|
Posted: Mar 18, 2004 5:42 AM
|
|
Hi,
Static variables are those that are declared static during declaration.
Example:
class VariableTest { int temporary = 1; static int permament = 1; }
Variables declared static are commonly shared across all instances of a class.
Variables declared static are commonly shared across all instances of a class. When you create multiple instances of VariableTest class This variable permament is shared across all of them. Thus, at any given point of time, there will be only one string value contained in the permament variable.
Since there is only one copy of the variable available for all instances, the code this.permament will result in compilation errors because it can be recalled that this.variablename refers to the instance variable name. Thus, static variables are to be accessed directly, as indicated in the code.
Hope this helps you to understand
|
|