PACKAGES
Single Type Import Declaration
7.5.1
7.5.1   Single Type Import Declaration
A
single type import declaration
imports a single type by giving its fully qualified
name, making it available under a simple name in the class and interface declara 
tions of its compilation unit.
SingleTypeImportDeclaration:
import
TypeName
 ;
The
TypeName
 must be the fully qualified name of a class or interface type; a
compile time error occurs if the named type does not exist. If the named type is
not in the current package, then it must be accessible ( 6.6) in an accessible
package and declared
public
 ( 8.1.2,  9.1.2) or a compile time error occurs.
The example:
import java.util.Vector;
causes the simple name
Vector
 to be available within the class and interface dec 
larations in a compilation unit. Thus, the simple name
Vector
 refers to the type
Vector
 in the package
java.util
 in all places where it is not hidden ( 6.3) by a
declaration of a field, parameter, or local variable with the same name.
If two single type import declarations in the same compilation unit attempt to
import types with the same simple name, then a compile time error occurs, unless
the two types are the same type, in which case the duplicate declaration is ignored.
If another type with the same name is otherwise declared in the current compila 
tion unit except by a type import on demand declaration ( 7.5.2), then a compile 
time error occurs.
So the sample program:
import java.util.Vector;
class Vector { Object[] vec; }
causes a compile time error because of the duplicate declaration of
Vector
, as
does:
import java.util.Vector;
import myVector.Vector;
where
myVector
 is a package containing the compilation unit:
package myVector;
public class Vector { Object[] vec; }
The compiler keeps track of types by their fully qualified names ( 6.7). Sim 
ple names and fully qualified names may be used interchangeably whenever they
are both available.
121






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