Answer to Question #259166 in Java | JSP | JSF for thando

Question #259166

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.











1
Expert's answer
2021-10-30T23:55:53-0400
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);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS