Hands-on practice for this lecture. Work through the exercises and quizzes to reinforce what you've learned.
Exercise 1 of 1
Avoid the inheritance trap. Verify if your child classes can truly substitute for their parents, or if you're building a system destined to crash.
"If it looks like a Duck and quacks like a Duck, but needs batteries, you probably have the wrong abstraction."
Select a bird to test the "makeItFly(Bird b)" method.
🦆 Liskov Substitution Principle: Child classes should be replaceable for their parent classes without causing errors. If a child "breaks" a parent method (e.g. by throwing an exception), your inheritance is logically flawed.
Practical exercises to master the concepts.
Create a Bird parent and a Ostrich child. Explain why Ostrich overriding fly() with an error violates LSP.