Java Reference
In-Depth Information
4 Polymorphic Behavior Provided by an Interface (continued)
Use the same test program, PolyTest.java, from Programming Assignment 3
to produce the same output as from Programming Assignment 3, by modifying
the classes according to the inheritance hierarchy displayed in Figure 10-62.
Change the abstract class, Bounceable, to an interface and modify the appropri-
ate concrete classes from the previous exercise to implement the new interface.
Ball
Bounceable
type
getType()
play()
bounce()
Bowlingball
Baseball
Tennisball
Basketball
FIGURE 10-62
5 Using Final Classes and Methods
Create the Java source code files for the classes listed in the inheritance hierarchy
displayed in Figure 10-63a. Create a new Java source code file and enter code for
the FinalTest.java test program, as shown in Figure 10-63b on page 686. Compile
all source code and execute the test program to obtain the output as displayed in
Figure 10-63c on page 686. Perform the following steps to complete these tasks:
1. The abstract base class, SecurityAlarm, has three constant values used for
the state of the alarm: no alarm, sensor failure, and activated alarm. One
method, alarmFailure(), cannot be overridden by any subclass. The other
two methods, alarm() and sensorSample(), are abstract.
2. The class, EntryAlarm, inherits from SecurityAlarm and has a single
constant value as a threshold. If the simulation of the alarm sensor exceeds
the threshold, the entry alarm is triggered. An EntryAlarm does not fail; it
either signals no alarm or it activates an alarm.
 
Search WWH ::




Custom Search