Java Reference
In-Depth Information
LISTING 10.7
continued
//-----------------------------------------------------------------
// Returns information about this hourly employee as a string.
//-----------------------------------------------------------------
public String toString()
{
String result = super .toString();
result += "\nCurrent hours: " + hoursWorked;
return result;
}
}
SELF-REVIEW QUESTIONS (see answers in Appendix N)
SR 10.3 How does inheritance support polymorphism?
SR 10.4 Suppose the class MusicPlayer is the parent of the class CDPlayer . Is
the following sequence of statements legal? Explain.
MusicPlayer mplayer = new MusicPlayer();
CDPlayer cdplayer = new CDPlayer();
mplayer = cdplayer;
SR 10.5 Suppose the class MusicPlayer is the parent of the class CDPlayer . Is
the following sequence of statements legal? Explain.
MusicPlayer mplayer = new MusicPlayer();
CDPlayer cdplayer = new CDPlayer();
cdplayer = mplayer;
SR 10.6 How is overriding related to polymorphism?
SR 10.7 Why is the StaffMember class in the Firm example declared as
abstract?
SR 10.8 Why is the pay method declared in the StaffMember class, given that it
is abstract and has no body at that level?
SR 10.9 Which pay method is invoked by the following line from the payday
method of the Staff class ?
amount = staffList[count].pay();
 
Search WWH ::




Custom Search