CS FundamentalsHardAccenture · GATE CS

A Square class extends Rectangle and overrides setWidth so that it also changes the height, breaking code that expects independent width and height. Which principle is violated?

  1. A. Liskov Substitution Principle
  2. B. Dependency Inversion Principle
  3. C. Single Responsibility Principle
  4. D. Interface Segregation Principle

Correct answer: A. Liskov Substitution Principle

A subclass must be usable wherever its base type is expected without breaking behaviour; Square surprises Rectangle clients.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic