From the course: Getting Started with Python Object Oriented Programming: A Hands-On Approach

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Polymorphism

Solution: Polymorphism

(upbeat music) - [Instructor] Here's the solution for the polymorphism challenge. So in our dog subclass, we need to create a method, make sound, and it takes self as an argument, and it's going to print woof. And with our cat subclass, we need to create the same method. I did tab again there, and it gave me far more code than I wanted. So sometimes using that autocomplete is not a good idea. But any hoo, it did complete the line I wanted. Print meow. Okay, so now when I run the code, I get woof and meow down in the console. Now this is a very simple example and very kind of contrived, but the basic idea is that we are learning how to override methods from a parent class in our subclasses.

Contents