Auto AdSense

Saturday, 24 January 2015

Python Object Oriented - Overriding Methods






  •       #!/usr/bin/python

    class Parent: # define parent class
       def myMethod(self):
         print 'Calling parent method'

    class Child(Parent): # define child class
       def myMethod(self):
         print 'Calling child method'

    c = Child() # instance of child
    c.myMethod() # child calls overridden method
  • Output
    Calling child method

No comments:

Post a Comment