CS FundamentalsHardProduct-company MCQ pattern

class Square extends Rectangle overrides setWidth() so that it also changes the height. Code that sets width = 5 and height = 4 on a Rectangle reference and expects area 20 now gets 16. Which SOLID principle is violated?

  1. A. Single Responsibility Principle
  2. B. Interface Segregation Principle
  3. C. Open/Closed Principle
  4. D. Liskov Substitution Principle

Correct answer: D. Liskov Substitution Principle

LSP says a subtype must be usable wherever its base type is expected without breaking correct behaviour. Square changes Rectangle's contract (independent width and height), so substituting it breaks the client.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic