Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint: shape dispatch

โญโญ intermediateโณ 25 min read๐Ÿ“ Lesson 120 of 256

Polymorphic totalArea โ€” one loop, dispatch does the branching.

totalArea is the inheritance synthesis in miniature: a Shape[] where every element answers area() in its own way, and the loop neither knows nor cares which concrete class it holds. If your trace needed instanceof, the dispatch table was missing โ€” the object's class already made the decision. This shape (one reference type, per-object behavior, one accumulator) is the entire inheritance MCQ genre compressed.