Implement the following class hierarchy on paper. You do not need to fill in the method bodies or include comments.
Solutions:
public interface Tossable { void toss(); }
public abstract class Ball implements Tossable { private String brandName; public Ball(String brandName) { } public String getBrandName() { } public abstract void toss(); public abstract void bounce(); }
public class Baseball extends Ball { public Baseball(String brandName) { } public void toss() { } public void bounce() { } }
public class Football extends Ball { public Football(String brandName) { } public void toss() { } public void bounce() { } }
public class Rock implements Tossable { public void toss() { } }
Answer the following questions:
Variable Type | ||||||
Throwable | Ball | Rock | Baseball | Football | ||
Object Type | Throwable | — | — | — | — | — |
Ball | — | — | — | — | — | |
Rock | ✓ | X | ✓ | X | X | |
Baseball | ✓ | ✓ | X | ✓ | X | |
Football | ✓ | ✓ | X | X | ✓ |