Classes, virtual methods ?
Erik Max Francis
max at alcyone.com
Fri May 16 04:18:32 EDT 2003
Rony wrote:
> if you have :
>
> Class A:
> def foo():
> print "in class A"
> Class B(A):
> def foo()
> print "in class B"
>
> m = B()
> print m.foo()
>
> You get 'in class B'
>
> Now my question
>
> Is there a way of calling foo of the master class of B with an
> instance of B
> I think this is called virtual methods ?
"Virtual" usually applies to the overriding of methods in subclasses,
which in Python is implicit (as you see here; calling m.foo() calls B's
foo, not A's).
> Something like (in another language)
> print m::A:foo()
> wich would give 'in class A'
You'd write
A.foo(m)
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ But when I reached the finished line / Young black male
\__/ Ice Cube
More information about the Python-list
mailing list