Python Object-Oriented Python Inheritance Super-Duper!

Andrew McLane
Andrew McLane
3,385 Points

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
203,995 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.