NAMES
Scope of a Simple Name
6.3
6.3   Scope of a Simple Name
The
scope
 of a declaration is the region of the program within which the entity
declared by the declaration can be referred to using a simple name:
The scope of a package, as introduced by a
package
 declaration, is deter 
mined by the host system ( 7.4.3). All Java code is within the scope of the
standard package named
java
, so the package
java
 can always be referred to
by Java code.
The scope of a type imported by a single type import declaration ( 7.5.1) or
type import on demand declaration ( 7.5.2) is all the class and interface type
declarations ( 7.6) in the compilation unit in which the import declaration
appears.
The scope of a type introduced by a class type declaration ( 8.1.1) or interface
type declaration ( 9.1.1) is the declarations of all class and interface types in
all the compilation units ( 7.3) of the package in which it is declared.
The scope of a member declared in or inherited by a class type ( 8.2) or inter 
face type ( 9.2) is the entire declaration of the class or interface type. The
declaration of a member needs to appear before it is used only when the use is
in a field initialization expression ( 8.3.2,  12.4.2,  12.5). This means that a
compile time error results from the test program:
class Test {
int i = j;
//
compile time error: incorrect forward reference
int j = 1;
}
whereas the following example compiles without error:
class Test {
Test() { k = 2; }
int j = 1;
int i = j;
int k;
}
even though the constructor ( 8.6) for
Test
 refers to the field
k
 that is
declared three lines later.
The scope of a parameter of a method ( 8.4.1) is the entire body of the
method.
81






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