Java includes the import statement to bring certain classes, or entire packages, into visibility. Once imported, a class can be referred to directly, using only its name… Read more »
Defining a Package
- PACKAGES:
Java provides a mechanism for partitioning the class name space into more manageable chunks. This mechanism is the package. The package is both a naming and a visibility control mechanism. You can define classes inside a package that are not accessible by code outside that package. You can also define class members that are only exposed to other members of the same package.
- Defining a package:
To create a package, include a package command as the first statement in a Java source file. Any classes declared within that file will belong to the specified package.
This is the general form of the package statement:
package pkg;
Here, pkg is the name of the package. For example, the following statement creates a package called MyPackage.
package MyPackage;
You can create a hierarchy of packages. To do so, simply separate each package name
from the one above it by use of a period. The general form:
package pkg1[.pkg2[.pkg3]];