🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Liskov Substitution
  2. B.Open-Closed
  3. C.Single Responsibility
  4. 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 →