endar class, which adds logging behavior in overriding addAppt() and ad-
Listing 2-30. Extending the appointment calendar class
public class LoggingApptCalendar extends ApptCalendar
// A constructor is not necessary because the Java com-
piler will add a
// noargument constructor that calls the superclass's
// constructor by default.
public void addAppt(Appt appt)
public void addAppts(Appt appts)
for (int i = 0; i < appts.length; i++)
void log(String msg) class method logs a string to a file (the details are un-
important). Notice the use of toString() to convert an Appt object to a String
object, which is then passed to log() .
Although this class looks okay, it does not work as you might expect. Suppose you
instantiatethisclassandaddafew Appt instancestothisinstancevia addAppts() ,
in the following manner: