We now write the subclasses of Item to represent the actual multimedia items (viz.
CDs (music) and DVDs (movies)) we store. There are two issues to consider for
these subclasses:
• Note the rules for constructors require a call to the superclass constructor.
The idea is to call the superclass constructor to initialize the fields in the
superclass.
• Use overridden methods for subclass specific behaviour. In particular we
need to override the toString method as this is different for each subclass.
We will also override the depreciate method since each item depreciates
differently.
public interface CDs {
default public int play(startButton button) {
System.out.println("Play the music");
}
}
public interface DVDs {
default public int play(startButton button) {
System.out.println("Play the movies");
}
}
public class Player implements CDs, DVDs {
public int play(startButton button) {
DVDs.super.play(button);
CDs.super.play(button);
}
}
Comments
Leave a comment