A class hierarchy organizes related classes through parent–child relationships. Shared attributes and behavior live in a parent class, while child classes add or specialize features. section 4.1.3 section 4.3
The arrangement becomes useful when an application supports several related objects. A Shape class can manage common initialization and movement, while Rectangle, Square, and Circle provide their own drawing behavior. section 4.1.3
A practical hierarchy develops through a few clear relationships:
- Rectangle inherits from Shape and overrides the empty draw() method with rectangle-specific rendering. section 4.1.3
- Square inherits from Rectangle because a square is treated as a special rectangle whose height and width match. section 4.1.3
- Circle inherits directly from Shape and supplies its own radius-based initialization and drawing behavior. section 4.1.3
- Child constructors can call super() to reuse parent initialization while translating child-specific inputs, such as size, into the parent’s parameters. section 4.1.3
A hierarchy for onscreen shapes
Shape holds common state and behavior. Rectangle reuses that foundation and implements draw(). Square extends Rectangle with one size value, while Circle extends Shape with a radius. The application can then draw all three shape types while retaining shared management in Shape. section 4.1.3



