Java Reference
In-Depth Information
Chapter 12 Self Test
1 . Enumeration constants are said to be self-typed . What does this mean?
2 . What class do all enumerations automatically inherit?
3 . Given the following enumeration, write a program that uses values( ) to show a list of
the constants and their ordinal values.
4 . The traffic light simulation developed in Try This 12-1 can be improved with a few
simple changes that take advantage of an enumeration's class features. In the version
shown, the duration of each color was controlled by the TrafficLightSimulator class
by hard-coding these values into the run( ) method. Change this so that the duration
of each color is stored by the constants in the TrafficLightColor enumeration. To do
this, you will need to add a constructor, a private instance variable, and a method
called getDelay( ) . After making these changes, what improvements do you see? On
your own, can you think of other improvements? (Hint: Try using ordinal values to
switch light colors rather than relying on a switch statement.)
5 . Define boxing and unboxing. How does autoboxing/unboxing affect these actions?
6 . Change the following fragment so that it uses autoboxing.
7 . In your own words, what does static import do?
8 . What does this statement do?
9 . Is static import designed for special-case situations, or is it good practice to bring all
static members of all classes into view?
10 . An annotation is syntactically based on a/an ________________.
11 . What is a marker annotation?
Search WWH ::




Custom Search