BLOCKS AND STATEMENTS
Scope of Local Variable Declarations
14.3.2
float[][][][] f;
float[][][][][] g;
float[][][] h;
We do not recommend such  mixed notation  for array declarations.
14.3.2   Scope of Local Variable Declarations
The scope of a local variable declared in a block is the rest of the block, including
its own initializer. The name of the local variable parameter may not be redeclared
as a local variable or exception parameter within its scope, or a compile time error
occurs; that is, hiding the name of a local variable is not permitted.
A local variable cannot be referred to using a qualified name ( 6.6), only a
simple name.
The example:
class Test {
static int x;
public static void main(String[] args) {
int x = x;
}
}
causes a compile time error because the initialization of
x
 is within the scope of
the declaration of
x
 as a local variable, and the local
x
 does not yet have a value
and cannot be used.
The following program does compile:
class Test {
static int x;
public static void main(String[] args) {
int x = (x=2)*2;
System.out.println(x);
}
}
because the local variable
x
 is definitely assigned ( 16) before it is used. It prints:
4
Here is another example:
class Test {
public static void main(String[] args) {
System.out.print("2+1=");
int two = 2, three = two + 1;
System.out.println(three);
}
}
267






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved