← Quiz: SOLID Principles: all 10 questions
Quiz: SOLID Principles · Question 4 of 10
Square extends Rectangle and changes setwidth so that it also sets the height. Code written for Rectangle now gives wro…
Square extends Rectangle and changes set_width so that it also sets the height. Code written for Rectangle now gives wrong areas. Which principle is broken?
- A.Liskov Substitution
- B.Open-Closed
- C.Single Responsibility
- D.DRY
Answer & explanation
Correct answer: Liskov Substitution
A subclass must be usable wherever the parent is expected without surprising the caller.
Can you get the rest right without peeking?
Take the timed Quiz: SOLID Principles quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →