Skip to content

A subclass that breaks its parent’s promises

Square extends Rectangle, overriding setWidth and setHeight so both dimensions always match. Existing code does:

r.setWidth(5); r.setHeight(4); assert r.area() == 20;

Given a Square, the assertion fails. Which principle is violated?