Python Forum

Full Version: superclass and super()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Viewer,

I have two questions related to inheritance:

1. Let's say I have a class A and another class B which is inheriting A. So B is the subclass of A. When instantiating the class B does the super class A also get instantiated?

2. When I am using super() in the sub class what does it actually contain? The reference of the subclass or a reference to the super class? The self parameter contains the reference to the current class. Similarly does super() contain the reference to the super class?

Please clarify.

Thanks.
1. No. You need to call the __init__ method for the super class from inside the __init__ method of the subclass. It is not called automatically.

2. In your example, calling super().__init__() from inside B.__init__ is the same as calling A.__init__(self). The argument for "self" is an instance of B, but remember that "B" is nothing but "A" with additional parts.