Java Reference
In-Depth Information
method is also called in the
ReboundPanel
constructor to begin the timer
countdown initially. The timer is never stopped in the
Rebound
program.
SR 9.30
a. The smiling face would move faster if the timer delay were decreased.
b. The smiling face would move slower if the timer delay were
increased. c. The image could be changed by specifying a new file in
the call to the
ImageIcon
constructor. d. The smiling face would make
larger jumps if the values of
moveX
and
moveY
were increased. e. The
smiling face would move faster when it hits the edge if, in the
action-
Performed
method, the timer delay were decreased in both of the
if
statements.
Chapter 10
Polymorphism
10.1
Late Binding
SR 10.1
Polymorphism is the ability of a reference variable to refer to objects
of various types at different times. A method invoked through such a
reference is bound to different method definitions at different times,
depending on the type of the object referenced.
SR 10.2
Compile time binding is considered more efficient than dynamic bind-
ing. Compile time binding occurs before the program is executed
and therefore does not delay the execution progress of the program.
Dynamic binding occurs while the program is running and therefore
does affect the runtime efficiency of the program.
10.2
Polymorphism via Inheritance
SR 10.3
In Java, a reference variable declared using a parent class can be used
to refer to an object of the child class. If both classes contain a method
with the same signature, the parent reference can be polymorphic.
SR 10.4
Yes, the statements are legal. Since a
CDPlayer
is a
MusicPlayer
, it
is legal to assign an object of class
CDPlayer
to a variable of class
MusicPlayer
.
SR 10.5
No, the third statement is not legal. A
MusicPlayer
is not necessarily
a
CDPlayer
. It is not legal to perform
cdplayer = mplayer
without
using an explicit
cast
operation. Consider that the
mplayer
variable
could potentially represent many different kinds of music players: CD
players, record players, mp3 players, etc. Suppose at the time of the
assignment statement, it represents an mp3 player. Then, you would
Search WWH ::
Custom Search