* A package provides a unique namespace for the types it contains.
* Classes in the same package can access each others package-access members.
Define a Package.
- Package pkg;[here pkg is the name of package ]
- Package pkg1[.pkg2[.pkg3[.pkg4]]];
This keyword is usually the first keyword in source file.
package java.awt.event;
To use a package's classes inside a Java source file, it is convenient to import the classes from the package with an import statement.
import java.awt.event.*;
imports all classes from the java.awt.event package, while the next statement
import java.awt.event.ActionEvent;
imports only the ActionEvent class from the package.
ActionEvent myEvent = new ActionEvent();
Classes can also be used directly without an import statement by using the fully-qualified name of the class.
java.awt.event.ActionEvent myEvent = new java.awt.event.ActionEvent();
No comments:
Post a Comment