A Java source file has the following elements in this specific order.
- An optional package statement. All classes and interfaces defined in the file belong to this package. If the package statement is not specified, the classes defined in the file belong to a default package. An example of a package statement is -
package testpackage;
- Zero or more import statements. The import statement makes any classes defined in the specified package directly available. For example if a Java source file has a statement importing the class "java.class.Button", then a class in the file may use Button class directly without providing the names of the package which defines the Button class. Some examples of import statement are -
import java.awt.*; // All classes in the awt package are imported.
import java.applet.Applet; - Any number of class and interface definitions may follow the optional package and import statements.
No comments:
Post a Comment