Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 21 Online
OpenStudy (anonymous):

Problem Set 5: In the solutions, why do the functions for SubjectTrigger and SummaryTrigger have __init__ functions defined? Don't they just inherit the ones that they define from their superclass anyway?

OpenStudy (anonymous):

To write it out, a superclass WordTrigger is created like so: class WordTrigger(Trigger): def __init__(self, word): self.word = word but then SubjectTrigger and SummaryTrigger have this defined: # TODO: SubjectTrigger class SubjectTrigger(WordTrigger): def __init__(self, word): WordTrigger.__init__(self, word) Isn't that unnecessary? Why is it there?

OpenStudy (rsmith6559):

WordTrigger inherits from Trigger, the __init__() function assigns the variable word into the instance of WordTrigger (the local namespace) being declared.

OpenStudy (anonymous):

But shouldn't that __init__() function be inherited anyway? I understand the purpose of __init__, but not why the valid one from the superclass is being overwritten by an identical one in the subclass.

OpenStudy (rsmith6559):

In that case, the __init__() function of the superclass is being overridden by the subclass, just like any other method.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!