Design Patterns · Middle · Question 19 of 75
Which of these situations violates the Liskov Substitution Principle?
- ✓Correct answer: A subclass overrides a method and throws "Not implemented"
- 2A subclass adds a new method that the parent doesn't have
- 3A subclass calls the parent implementation via
super
Explanation
Code working with the base type doesn't expect an exception - substitution breaks the program. It's usually a sign that the hierarchy is wrong and the interface should be split (ISP). LSP doesn't forbid adding new methods.