OOP: method overriding works in mysterious ways?
John M. Gabriele
john_sips_teaz at yahooz.com
Mon Jan 2 18:24:29 EST 2006
André wrote:
> John M. Gabriele wrote:
>
> Since Child has no advice() method, it inherits the one for Parent.
> Thus, Child can be thought of as being defined as follows:
>
> . class Child( Parent ):
> .
> . def speak( self ):
> . print '\t\tChild.speak()'
> . self.advise()
> .
> . def advise( self ): # inherited from Parent
> . print '\tParent.advise()'
> . self.critique()
> .
> . def critique( self ):
> . print '\t\tChild.critique()'
> .
That's a very interesting way to look at it... But I thought
that the Python interpreter takes care of walking up the
inheritance tree looking for the instance methods, rather
than what you've written above...
> Note that "self" refer to the *instance* created, not the *class*.
Thanks. Right -- the self object always refers to the object that
you originally used to call the instance method (here, speak()).
>
> Now, does the output make sense?
>
> André
>
Bearing in mind what self is referring to, then yes,
the output does make sense. Thanks. :)
---J
--
(remove zeez if demunging email address)
More information about the Python-list
mailing list