ProgrammingHardProduct-company placement · GATE CS

Account.withdraw(amount) works for any amount up to the balance. A subclass FixedDeposit overrides it to throw an exception unless the amount is a multiple of 1000. Code written for Account now fails when given a FixedDeposit. Which principle is broken, and how?

  1. A. Liskov Substitution, because the subclass strengthened the method's precondition
  2. B. Open/Closed, because FixedDeposit modified the base class
  3. C. Interface Segregation, because withdraw is too large an interface
  4. D. Dependency Inversion, because the client depends on a concrete class

Correct answer: A. Liskov Substitution, because the subclass strengthened the method's precondition

A subtype may weaken preconditions and strengthen postconditions, never the reverse. Requiring multiples of 1000 rejects inputs the base contract accepts, so a FixedDeposit cannot stand in for an Account.

More OOP with C++ and Java questions

Exams that ask this topic