Overriding Methods through Inheritance : Subclass : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Subclass »

 

Overriding Methods through Inheritance


class P(object):
    def foo(self):
        print 'Hi, I am P-foo()'

p = P()
print p.foo()

class C(P):
    def foo(self):
        print 'Hi, I am C-foo()'

c = C()
print c.foo()

P.foo(c)

class C(P):
    def foo(self):
        super(C, self).foo()
        print 'Hi, I am C-foo()'

c = C()
print c.foo()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Subclass