I'd like to assign a data attribute to an instance of my super class taken at instantiation.
For example:
class Sub(Super):
def __init__(self, name):
self.name = Super.__init__(self, name)
In other words, I want to use as my name
what the superclass Super
yields.
Is this practice frowned upon? I didn't see any other posts using this syntax, but can't figure how I would otherwise use an instance of my superclass during instantiation.
There's no point to passing in a reference to the superclass of an object in the constructor. Your subclass is already an instance of the superclass.
Even though you can't directly see the private components of the superclass, but they still exist and calls to public accessor methods will still produce normal behavior.
In other words, there is no need to pass name
into the superclass Super
More Info here: https://www.tutorialspoint.com/what-happens-when-a-subclass-object-is-assigned-to-a-superclass-object-in-java