7.6
Type Declarations
PACKAGES
import Vector.Mosquito;
class Test {
public static void main(String[] args) {
System.out.println(new Vector().getClass());
System.out.println(new Mosquito().getClass());
}
}
the single type import declaration ( 7.5.1) importing class
Vector
from package
java.util
does not prevent the package name
Vector
from appearing and being
correctly recognized in subsequent
import
declarations. The example compiles
and produces the output:
class java.util.Vector
class Vector.Mosquito
7.6 Type Declarations
A type declaration declares a class type ( 8) or an interface type ( 9):
TypeDeclaration:
ClassDeclaration
InterfaceDeclaration
;
A Java compiler must ignore extra
;
tokens appearing at the level of type
declarations. Stray semicolons are permitted in Java solely as a concession to C++
programmers who are used to writing:
class date { int month, day, year; };
(In C++, but not in Java, one can provide a comma separated list of identifiers in
order to declare variables between the
}
and the
;
.) Extra semicolons should
not be used in new Java code. Software that reformats Java code can delete them.
By default, the types declared in a package are accessible only within the
compilation units of that package, but a type may be declared to be
public
to
grant access to the type from code in other packages ( 6.6, 8.1.2, 9.1.2).
A Java implementation must keep track of types within packages by their
fully qualified names ( 6.7). Multiple ways of naming a type must be expanded to
fully qualified names to make sure that such names are understood as referring to
the same type. For example, if a compilation unit contains the single type import
declaration ( 7.5.1):
import java.util.Vector;
124
footer
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