Java Scopes
Most programming languages provide the concept of a scope. For names defined in the scope, the scope also determines
Its "visibility" and "presence Time". In C,c++ and Java, scopes are determined by the position of curly braces. Refer to the following
Example:
As a variable defined in the scope, it can only be used until the end of that scope.
In the example above, indented typography makes Java code easier to read. Since Java is a free-form language, extra spaces,
Neither the table bit nor the carriage return will affect the resulting program.
Note that although it is legal in C and C + +, it is not possible to write code like this in Java:
The compiler will assume that the variable x is already defined. So C and C + + can "hide" a variable in a larger scope. But this approach is
Java is not allowed, because the Java designers think this makes the program confusing.
From think in Java P50
[Learning note Java scope Variable declaration and C, C + + differences