Java Reference
In-Depth Information
float x = 3.14f, y = 2.81f;
is the same as the more readable
float x = 3.14f,
y = 2.81f;
is the same as the preferred
float x = 3.14f;
float y = 2.81f;
Field variables are members of classes, or interfaces, and are declared
within the body of that class or interface. Fields can be initialized with
an initializer, within an initialization block, or within a constructor, but
need not be initialized at all because they have default initial values, as
discussed on page 44 . Field initialization and the modifiers that can be
applied to fields were discussed in Chapter 2 .
Local variables can be declared anywhere within a block of statements,
not just at the start of the block, and can be of primitive or reference
type. As a special case, a local variable declaration is also permitted
within the initialization section of a for loopsee " for " on page 236 . A local
variable must be assigned a value before it is used. [7] There is no default
initialization value for local variables because failure to assign a start-
ing value for one is usually a bug. The compiler will refuse to compile
code that doesn't ensure that assignment takes place before a variable
is used:
[7] In technical terms there is a concept of a variable being "definitely assigned." The compiler won't
allow the use of a local variable unless it can determine that it has been definitely assigned a value.
int x; // uninitialized, can't use
int y = 2;
 
 
Search WWH ::




Custom Search