Problem

Playing Compilera. Suppose that each of the classes, CD, DVD, and MP3 implements two inter...

Playing Compiler

a. Suppose that each of the classes, CD, DVD, and MP3 implements two interfaces, Playable and Source:

    public interface Playable       public interface Source    {                               {      public void play();             public void source();    }                               }

Is there any problem with the code for the method printList(5) of Short Exer­cise 2? Explain why or why not.


b. What errors, if any, occur if we substitute the following code for the shape.draw(1, 1) method call on line 22 of Example 13.2? Explain your answer.

    if (shape instanceof Square)          ((Square)shape).draw(1, 1);    else if (shape instanceof RightTriangle)          ((RightTriangle)shape).draw(1, 1);    else if (shape instanceof Triangle)          ((Triangle)shape).draw(1, 1);

How about this replacement code? Explain your answer.

    if (shape instanceof Square)          shape.draw(1, 1);    else if (shape instanceof RightTriangle)          shape.draw(1, 1);    else if (shape instanceof Triangle)          shape.draw(1, 1);

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 13
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT