Java Reference
In-Depth Information
Final Thoughts on Packages and Interfaces
Although the examples we've included in this topic do not make frequent use of packages
or interfaces, both of these tools are an important part of the Java programming environ-
ment. Virtually all real programs that you write in Java will be contained within packages.
A number will probably implement interfaces as well. It is important, therefore, that you
be comfortable with their usage.
Chapter 8 Self Test
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 .
2 . What is a namespace? Why is it important that Java allows you to partition the
namespace?
3 . Packages are stored in ______________.
4 . Explain the difference between protected and default access.
5 . Explain the two ways that the members of a package can be used by other packages.
6 . “One interface, multiple methods” is a key tenet of Java. What feature best exempli-
fies it?
7 . How many classes can implement an interface? How many interfaces can a class im-
plement?
8 . Can interfaces be extended?
9 . Create an interface for the Vehicle class from Chapter 7 . Call the interface IVehicle .
10 . Variables declared in an interface are implicitly static and final . Can they be shared
with other parts of a program?
11 . A package is, in essence, a container for classes. True or False?
12 . What standard Java package is automatically imported into a program?
13 . What keyword is used to declare a default interface method?
14 . Beginning with JDK 8, is it possible to define a static method in an interface ?
Search WWH ::




Custom Search