Java Reference
In-Depth Information
A package may not contain two members of the same name, or a compile-time error results.
Here are some examples:
• Because the package
java.awt
has a subpackage
image
, it cannot (and does not)
contain a declaration of a class or interface type named
image
.
• If there is a package named
mouse
and a member type
Button
in that package
(which then might be referred to as
mouse.Button
), then there cannot be any
package with the fully qualified name
mouse.Button
or
mouse.Button.Click
.
• If
com.nighthacks.java.jag
is the fully qualified name of a type, then there can-
not be any package whose fully qualified name is either
com.nighthacks.java.jag
or
com.nighthacks.java.jag.scrabble
.
It is however possible for members of different packages to have the same simple
name. For example, it is possible to declare a package:
package vector;
public class Vector { Object[] vec; }
that has as a member a
public
class named
Vector
, even though the package
java.util
also
declares a class named
Vector
. These two class types are different, reflected by the fact
example
Vector
is
vector.Vector
, whereas
java.util.Vector
is the fully qualified name of the
Vector
class included in the Java SE platform. Because the package
vector
contains a
class named
Vector
, it cannot also have a subpackage named
Vector
.
The hierarchical naming structure for packages is intended to be convenient for organizing
related packages in a conventional manner, but has no significance in itself other than the
prohibition against a package having a subpackage with the same simple name as a top
For example, there is no special access relationship between a package named
oliver
and another package named
oliver.twist
, or between packages named
evelyn.wood
and
evelyn.waugh
. That is, the code in a package named
oliver.twist
has no better access to
the types declared within package
oliver
than code in any other package.
7.2. Host Support for Packages
Each host system determines how packages and compilation units are created and stored.