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.

Challenge: Class inheritance

Challenge: Class inheritance

(cheerful music) - [Instructor] Welcome to the challenge for chapter five. So you're going to be given a base class called, Animal and it's going to have properties name and sound and a method called make_sound to print the sound. And I'll show you the code for this now. So you can see here the class definition. Your task is going to be to create two subclasses from that Animal base class. These subclasses are going to contain additional methods. So the Dog subclass is going to have a wag_tail method, which is going to print a message like Dusty's tail is wagging, for example, if the name of the dog is Dusty. And the Cat subclass is going to have a purr method, which is going to print something like Suki is purring if your cat is called Suki. You'll find some boilerplate code for this challenge. So you can see we have a description of the task at the top from lines one to eight, and then we have our base class starting on line 14. That's what we showed you on the slide. Now, your task…

Contents