Java Reference
In-Depth Information
FIGURE 10-60b
FIGURE 10-60c
3 Polymorphic Behavior Provided by Inheritance
Create the Java source code files for the classes listed in the inheritance hierarchy
displayed in Figure 10-61a on the next page. Create a new Java source code file
and enter code for the PolyTest.java test program, as shown in Figure 10-61b on
page 683. Compile all source code and execute the test program to obtain the
output as displayed in Figure 10-61c on page 683. Perform the following steps to
complete these tasks:
1. Create an abstract base class, Ball. The single constructor requires a String to
indicate the type of ball, which then is stored in an instance variable. The
instance method, getType(), returns a new String containing the type of ball.
The class declares an abstract method, play(), which returns void.
Search WWH ::




Custom Search