Java Reference
In-Depth Information
Chapter 8: Packages and Interfaces
1
.
Using the code from
Try This 8-1
, put the
ICharQ
interface and its three implement-
ations into a package called
qpack
. Keeping the queue demonstration class
IQDemo
in the default package, show how to import and use the classes in
qpack
.
To put
ICharQ
and its implementations into the
qpack
package, you must separate
each into its own file, make each implementation class
public
, and add this statement
to the top of each file.
Once this has been done, you can use
qpack
by adding this
import
statement to
IQDemo
.
namespace?
A namespace is a declarative region. By partitioning the namespace, you can prevent
name collisions.
directories
A member with
protected
access can be used within its package and by a subclass in
any package.
A member with default access can be used only within its package.
To use a member of a package, you can either fully qualify its name, or you can im-
port it using
import
.
fies it?
The interface best exemplifies the one interface, multiple methods principle of OOP.
plement?
An interface can be implemented by an unlimited number of classes. A class can im-
plement as many interfaces as it chooses.