Skip to main content

Practice · 2 of 3

Abstract shapes with conditional overrides

CHALLENGE
Difficulty: advanced+25 XP

Implement Shape (abstract): public abstract int area(); plus a concrete describe() returning "shape:" + area(). Subclass Square (side; area = side*side) and Rect (w, h; area = w*h). Then implement totalArea(ArrayList<Shape>). The list may contain both; use the abstract reference type.

Back to lesson: Practice: Polymorphism gauntlet