SCJP Certification

Sun Certified Java Programmer Certification exam essentials

October 28th, 2009

How to declare a package?

Java Facts, by Daisy Williams.

The package statement is used to declare packages. The word package is a keyword in Java. This statement is not technically needed to write a complete Java program. However, if it appears, it must be the first executable statement in the program. Only comments or white spaces are allowed before a package statement. There can be only one package declaration in a program. If no package declaration appears, the class will belong to the default package.

For example, the following source code file defines a class named ClassA in the package named package4:

package package4;

public class ClassA{
{
// body code
}

This source file will be saved with the name ClassA.java in the directory named package4.

Share

Back Top

Responses to “How to declare a package?”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*