Packages and Interfaces  «Prev  Next»
Lesson 4Packaging Java classes
ObjectiveOrganize Java Classes into Packages

Organize Java Classes into Packages

The package statement is used to identify the package to which a class belongs.
This statement must be placed at the beginning of the source code file for the class. Following is an example of a package statement:

package toys;

Placed at the beginning of a source code file for a class, this statement indicates that the class belongs to the toys package. If you wanted to include classes named finky and slinky in the toys package, you would place the above package statement at the top of the source code files for each class.
Even though the package statement must be placed at the beginning of a source file, it is okay to have comments appearing before it in the code.

Java Classes - Quiz

Click the Quiz link below to test your knowledge of packages.
Java Classes - Quiz