Java Reference
In-Depth Information
7.6. Top Level Type Declarations
A top level type declaration declares a top level class type (§8) or a top level interface type
(§9).
TypeDeclaration:
ClassDeclaration
InterfaceDeclaration
;
By default, the top level types declared in a package are accessible only within the com-
pilation 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.1 , § 9.1.1 ).
It is a compile-time error if a top level type declaration contains any one of the following
access modifiers: protected , private , or static .
It is a compile-time error if the name of a top level type appears as the name of any other
top level class or interface type declared in the same package.
It is a compile-time error if the name of a top level type is also declared as a type by a
single-type-import declaration (§ 7.5.1 ) in the compilation unit containing the type declara-
tion.
Example 7.6-1. Conflicting Top Level Type Declarations
Click here to view code image
package test;
import java.util.Vector;
class Point {
int x, y;
}
interface Point { // compile-time error #1
int getR();
int getTheta();
}
class Vector { Point[] pts; } // compile-time error #2
Here, the first compile-time error is caused by the duplicate declaration of the name
Point as both a class and an interface in the same package. A second compile-time
error is the attempt to declare the name Vector both by a class type declaration and by
a single-type-import declaration.
Search WWH ::




Custom Search