Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAndrew McLane
3,385 PointsDoesn'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
231,198 PointsYou 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.