Java Reference
In-Depth Information
set, nor for a local variable of type double to contain an element of the double-extended-ex-
ponent value set that is not also an element of the double value set.
The scope and shadowing of a local variable is specified in § 6.3 and § 6.4 .
14.4.2. Execution of Local Variable Declarations
A local variable declaration statement is an executable statement. Every time it is executed,
the declarators are processed in order from left to right. If a declarator has an initialization
expression, the expression is evaluated and its value is assigned to the variable.
If a declarator does not have an initialization expression, then every reference to the
variable must be preceded by execution of an assignment to the variable, or a compile-
time error occurs by the rules of §16.
Each initialization (except the first) is executed only if evaluation of the preceding initial-
ization expression completes normally.
Execution of the local variable declaration completes normally only if evaluation of the last
initialization expression completes normally.
If the local variable declaration contains no initialization expressions, then executing it al-
ways completes normally.
14.5. Statements
There are many kinds of statements in the Java programming language. Most correspond
to statements in the C and C++ languages, but some are unique.
As in C and C++, the if statement of the Java programming language suffers from the so-
called “dangling else problem,” illustrated by this misleadingly formatted example:
Click here to view code image
if (door.isOpen())
if (resident.isVisible())
resident.greet("Hello!");
else door.bell.ring(); // A "dangling else"
The problem is that both the outer if statement and the inner if statement might conceivably
own the else clause. In this example, one might surmise that the programmer intended the
else clause to belong to the outer if statement.
Search WWH ::




Custom Search