Let the Animals Talk
where the name of the animal,
self.name, inside of the curly braces says the
.sound in the curly braces. And I don’t want this to fail if you don’t pass an argument to
.sound, so I’ll give it a default argument of, well, what does every animal do? I guess they all sleep.
So I’ll put in there. That’s my default argument. So this is really just a protection for me that if someone implements the
.talk() method in one of the child classes but doesn’t pass in a default sound and then someone calls it without a default sound, I don’t want this to break. So that’s why we have a default in here.
But I’m going to go ahead and override that right away in all of the classes that I have so far. So let’s do a bit of extending a method. I have
.talk() in the child class
Dog, and it’ll take
And otherwise I don’t need to write that string again so that I can change it in the parent class, and it’ll trickle down to all of the child classes. I’m going to call
super() and then the
.talk() method of
super() and pass it the
02:08 Okay, so this should give me the possibility to have each instance of each of those three child classes talk and give a different default sound. But also I can still pass in a sound and then make them say whatever they want.
Become a Member to join the conversation.