Multiple ChoiceIntermediate 45s
LSP: the invariant about preconditions
A base class method promises to accept any amount >= 0. A subclass override rejects 0 and throws. Why is this an Liskov violation?
Options
- 1The subclass override runs more slowly than the base method. It validates its argument first on every call.
- 2The subclass override returns a different concrete type. The base declares a different return type in its signature.
- 3The subtype strengthened a precondition, so callers written against the base contract can now fail
- 4The subclass declares an extra helper method. The base never announced that method in its contract.
Think you can answer under pressure?
Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.