oop - object oriented programming basics: inheritance & shadowing (Python) -


Level: Beginners

I am making my first step in Object Oriented Programming. This code is for the purpose of showing how the series is crossed. So when I call UG.say (person, 'but I like'), then call method to call the class MITPerson Instructions have been given. Given that there is no call method in MITPerson , it will pass it to class person . I think there is nothing wrong with the code because it is part of a lecture (see source below). I think it's me to leave something to define when I run the code. Not sure what though that I think the UG example is looking for an error message because in the first argument it is a matter of self but in theory, there is no need to provide Is it right? Any signals?

  class person (object): def __init __ (self, family_name, first_name): self. Family_name = family_name self first name = first_name dff family name (self): return self.family_name def first name (self): back self First_name Def (self, toWhom, some): Returns to self.first_name + '' + self.family_name + '' towhom.first_name () + '' towhom.familyName () + ':' + Some class MITPser (Person): DF __int __ (self, family name, first name): person .__ init __ (self, family name, first name) class UG (MITPerson): def __init __ (self, family name, first name): MITPS __int __ (self, family name, first name) self.year = nobody says no DF (self, left, some): return MITPISIS. (Self, voum, 'sorry, but some') & gt; & Gt; & Gt; Person = person ('zone', 'dow') & gt; & Gt; & Gt; Person_mit = MITPerson ('Quin', 'Eil') & gt; & Gt; & Gt; Ug = UG ('Dialan', 'Bob') & gt; & Gt; & Gt; UG.say (person, 'but I like') UG (Person, 'blay') ** Edit (for completeness) **: It should be said UG (person, 'but I like) # # Bla' The last test type is wrapped with airlold: unbound method () Should be known as the first argument with UG Instance (example of person for example)  

Source: MIT OpenCareware Computer Science Programming Fall 2008

You are calling class instead of example.

  & gt; & Gt; & Gt; Ug = UG ('Dialan', 'Bob') & gt; & Gt; & Gt; UG.say (person, 'but I like') UG (Person, 'Blaise')  

Instead of call instances

  & gt; & Gt; & Gt; Ug = UG ('Dialan', 'Bob') & gt; & Gt; & Gt; Ug.say (person, 'but I like')  

Comments