Packages and Permissions
Packages
- A package is a collection of classes (types) and,
possibly, subpackages.
java
is a package that contains the subpackage
java.lang
.
java.lang
contains about 50 classes and several subpackages.
- A package hierarchy corresponds to a file system hierarchy on
disk. In Windows, substitute '\' for '.' in the package name.
- You can name the package that the classes in a compilation unit
belong to using the
package
statement at the beginning of
the file.
- Use
import
statements to name classes whose members
you want to reference without having to specify the fully-qualified
member name.
- All the compilation units in the same directory are part of the
same unnamed package unless you use a
package
statement
in some (or all) of them.
Permissions
- A public class or member can be referenced outside its
package.
- A protected class or member can be referenced only inside
its own class or from within a subclass.
- A private class or member can be referenced only from
inside the class that it is defined in.