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 Inheritance Super-Duper!

Doesn't __init__ redefined in the subclass override the super classes init?

Not sure why we have to redefine init in the subclass if we can just call it using the super() from the parent class. Also, if we want to modify our child's init why don't we just put whatever we want to happen in its own init, if that is overriding the parent's init.

I thought that the Thief class could act independently if none of the parent's classes were called but the video makes it sound like the parent's init is going to run in the child class immediately.

I guess I might have a fundamental confusion about what init is and how it initializes the class.

1 Answer

Steven Parker
Steven Parker
210,423 Points

You are correct that redifining __init__ overrides the parent. That's why you would call the parent's version using "super" from inside it.

And the reason for not making it completely independent is to keep the code "dry" and not duplicate functionality the the parent can perform already. The main reason to override __init__ and also call the parent version is to add some additional functionality and/or change the instantiation signature.