*# definition of subclass 1*
class Student(Person):
def __init__(self, student_name, student_age):
Person.__init__(self, student_name, student_age)
*# definition of subclass 2*
class Student(Person):
def __init__(self, student_name, student_age):
super().__init__(student_name, student_age)
self
always needs to be passed into a method so that the method can actually access and make changes to the class properties. Self is effectively the representative for the class inside of itself, and so you cannot âinheritâ self
from another class, as you want it to refer to itself. As super()
is used to inherit properties and methods from the parent class, you donât want to inherit the parent classâ self
, therefore it is not contained within the super()
.
For a quick analogy, you inherit certain things from your parents when you are born, however you cannot inherit their âexistenceâ so to speak. You are independent individuals, and so even if you inherit a bunch of attributes from them like hair colour and eye colour, you donât âinheritâ being a living person, as you just are!
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.