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 Exercise 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);
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.