Java Reference
In-Depth Information
good programming practice requires that the programmer satisfy herself that despite
any unchecked warning, the code is correct and heap pollution will not occur.
4.12.3. Kinds of Variables
There are seven kinds of variables:
1. A class variable is a field declared using the keyword static within a class declara-
tion (§ 8.3.1.1 ), or with or without the keyword static within an interface declaration
9.3 ) .
A class variable is created when its class or interface is prepared (§ 12.3.2 ) and is
initialized to a default value (§ 4.12.5 ) . The class variable effectively ceases to exist
when its class or interface is unloaded (§ 12.7 ).
2. An instance variable is a field declared within a class declaration without using the
keyword static 8.3.1.1 ) .
If a class T has a field a that is an instance variable, then a new instance variable a
is created and initialized to a default value (§ 4.12.5 ) as part of each newly created
object of class T or of any class that is a subclass of T 8.1.4 ) . The instance vari-
able effectively ceases to exist when the object of which it is a field is no longer
referenced, after any necessary finalization of the object (§ 12.6 ) has been com-
pleted.
3. Array components are unnamed variables that are created and initialized to default
values (§ 4.12.5 ) whenever a new object that is an array is created (§10, § 15.10 ).
The array components effectively cease to exist when the array is no longer refer-
enced.
4. Method parameters 8.4.1 ) name argument values passed to a method.
For every parameter declared in a method declaration, a new parameter variable is
created each time that method is invoked (§ 15.12 ). The new variable is initialized
with the corresponding argument value from the method invocation. The method
parameter effectively ceases to exist when the execution of the body of the method
is complete.
5. Constructor parameters 8.8.1 ) name argument values passed to a constructor.
For every parameter declared in a constructor declaration, a new parameter vari-
able is created each time a class instance creation expression (§ 15.9 ) or explicit
constructor invocation (§ 8.8.7 ) invokes that constructor. The new variable is ini-
tialized with the corresponding argument value from the creation expression or
constructor invocation. The constructor parameter effectively ceases to exist when
the execution of the body of the constructor is complete.
Search WWH ::




Custom Search