Extend a Method (Exercise)
Your second review exercise asks you to extend a method from the parent class. Give the
sound argument of
GoldenRetriever.speak() a default value of
"Bark", the string
"Bark". And again, you’re going to use the same
Dog class as your parent class.
What you’re going to need to do here is to work with method overriding or extending. So you want to do something with the
.speak() method from the
Dog parent class, and you can see that it takes a
sound as an argument, and you want to provide a default argument for
So the child class called
GoldenRetriever should have a default argument that the parent
Dog class doesn’t have, so that if you don’t pass anything to
.speak() on a
GoldenRetriever object, then it should always say
"Bark". Okay, that’s the task.
Become a Member to join the conversation.