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?
- A. Single Responsibility Principle
- B. Interface Segregation Principle
- C. Open/Closed Principle
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A ReportService creates a new MySqlDatabase() directly inside its constructor. Refactoring it to receive a Database interface through its…
- Which HTTP method is NOT idempotent by definition?
- A logged-in user with a valid token calls an admin-only API endpoint. Which status code should the server return?
- In the IaaS model (for example a plain cloud virtual machine), which of these is the customer's responsibility rather than the provider's?
- A Scrum team's last three sprints delivered 28, 32 and 30 story points. 240 points remain in the backlog and sprints are 2 weeks long…
- Using basic COCOMO for an organic project (E = 2.4 × KLOC^1.05 person-months), what is the estimated effort for a 32 KLOC project?