ATHENA
Java Lab Workbook / Smart Reader
THE ATHENA LIBRARY

Java Lab Workbook

CS 220 Teaching Team · practice set

Lab 6

Shapes and dynamic dispatch

Create an abstract class Shape with an abstract method area(). Implement Circle, Rectangle and Triangle.

Store instances in a List<Shape> and compute the total area in a single loop. Do not use instanceof.

Extension: add an interface Drawable and make two of the shapes implement it. Explain which calls the compiler permits on a Shape reference.

Fictional educational sample written for the Athena demo · Page 48 of 120.

100%saved