Java Reference
In-Depth Information
7.3. Variables
which a value can be assigned. Variables include fields, local variables in
a block of code, and parameters. A variable
declaration
states the iden-
tifier (name), type, and other attributes of a variable. The type part of a
declaration specifies which kinds of values and behavior are supported by
the declared entity. The other attributes of a variable include
annotations
and
modifiers.
Annotations can be applied to any variable declaration and
are discussed in
Chapter 15
.
[6]
Type variables
are not storage locations and are excluded from this discussion. They apply only to
generic type declarations and are discussed in
Chapter 11
.
7.3.1. Field and Local Variable Declarations
Fields and local variables are declared in the same way. A declaration is
broken into three parts:
modifiers,
followed by a
type,
followed by a list
of
identifiers.
Each identifier can optionally have an
initializer
associated
with it to give it an initial value.
There is no difference between variables declared in one declaration or in
multiple declarations of the same type. For example:
float x, y;
is the same as
float x;
float y;
Any initializer is expressed as an assignment (with the
=
operator) of an
expression of the appropriate type. For example: