Skip to Content

What Does Liskov Substitution Principle State in OOP Design?

LSP Explained: Subclass Replacement Without Breaking Code?

Liskov Substitution Principle mandates superclass objects replaceable by subclasses without altering program correctness, ensuring robust inheritance and polymorphism in object-oriented design.

Question

What does the Liskov Substitution Principle state in the context of object-oriented design?

A. A class should have only one reason to change
B. Interfaces should segregate methods not used by clients
C. Objects of a superclass should be replaceable with objects of a subclass without affecting the correctness
D. Software entities should be open for extension but closed for modification

Answer

C. Objects of a superclass should be replaceable with objects of a subclass without affecting the correctness

Explanation

The Liskov Substitution Principle (LSP), part of SOLID design principles, requires that subclasses maintain behavioral compatibility with their superclasses, preserving preconditions, postconditions, invariants, and expected contracts so any code relying on the parent type functions correctly when substituted with child instances. This ensures reliable polymorphism and inheritance hierarchies without unexpected failures, distinguishing it from Single Responsibility (A) for focused changes, Interface Segregation (B) for client-specific methods, or Open/Closed (D) for extension without modification.