Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python (retired) Inheritance Override Inherited Methods

Dhruv Ghulati
Dhruv Ghulati
1,582 Points

Why can I not override Animal.noise just like I override Animal.sound, via creating a new method in the class to overide

Is there a reason why def noise(self) here is not working? def sound(self) did work in its override...

from animal import Animal

class Sheep(Animal):

  def sound(self):

  def noise(self):

1 Answer

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

You should be changing the sound attribute in the class, not providing a sound() method (that that passes shows me I need to add another check to the challenge. Thanks for finding that!). Finally, in noise(), you need to return the uppercased version of the sound. What you're doing now is changing the method to an attribute...sorta. It's just erroring out due to that being invalid code.

Dhruv Ghulati
Dhruv Ghulati
1,582 Points

Thanks. This helped and I completed the challenge :)