Bird
Raised Fist0

Which of the following statements about the Liskov Substitution Principle is INCORRECT?

medium🐞 Bug Identification Q14 of Q15
OOP & Design Patterns - Liskov Substitution Principle - Subtype Behavioural Contract
Which of the following statements about the Liskov Substitution Principle is INCORRECT?
AA subclass can strengthen preconditions of an inherited method to ensure better input validation.
BA subclass must not weaken postconditions of an inherited method.
CCovariance in return types is allowed under LSP.
DContravariance in method parameter types is allowed under LSP.
Step-by-Step Solution
  1. Step 1: Recall LSP precondition rule

    Subclasses must not strengthen preconditions; they can only maintain or weaken them.
  2. Step 2: Analyze each statement

    A subclass can strengthen preconditions of an inherited method to ensure better input validation. is incorrect because strengthening preconditions breaks substitutability. A subclass must not weaken postconditions of an inherited method. is correct; subclasses can weaken postconditions. Covariance in return types is allowed under LSP. is correct; covariance in return types is allowed. Contravariance in method parameter types is allowed under LSP. is correct; contravariance in parameter types is allowed.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Strengthening preconditions violates LSP.
Quick Trick: Preconditions can only be weakened, not strengthened, in subclasses.
Common Mistakes:
MISTAKES
  • Confusing precondition and postcondition rules
  • Believing strengthening preconditions is safe
  • Misunderstanding covariance and contravariance
Trap Explanation:
PITFALL
  • Option A is tempting because better validation seems positive, but it breaks substitutability; other options reflect correct LSP rules.
Interviewer Note:
CONTEXT
  • Tests candidate's precise understanding of behavioral contract rules in LSP.
Master "Liskov Substitution Principle - Subtype Behavioural Contract" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes