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 .
2 . What is a namespace? Why is it important that Java allows you to partition the
namespace?
A namespace is a declarative region. By partitioning the namespace, you can prevent
name collisions.
3 . Packages are stored in __________.
directories
4 . Explain the difference between protected and default access.
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.
5 . Explain the two ways that the members of a package can be used by other packages.
To use a member of a package, you can either fully qualify its name, or you can im-
port it using import .
6 . “One interface, multiple methods” is a key tenet of Java. What feature best exempli-
fies it?
The interface best exemplifies the one interface, multiple methods principle of OOP.
7 . How many classes can implement an interface? How many interfaces can a class im-
plement?
An interface can be implemented by an unlimited number of classes. A class can im-
plement as many interfaces as it chooses.
Search WWH ::




Custom Search