Class inherited : Class Inheritance : Class : Python examples (example source code) Organized by topic

C++
PHP
Python
Python Home »  Class   » [  Class Inheritance  ]  Screenshots 
 



Class inherited



class FirstClass:                 # define a class object
     def setdata(self, value):    # define class methods
         self.data = value        # self is the instance
     def display(self):
         print self.data          # self.data: per instance

class SecondClass(FirstClass):                     # inherits setdata
     def display(self):                            # changes display 
         print 'Current value = "%s"' % self.data

z = SecondClass()
z.setdata(42)           # setdata found in FirstClass
z.display()             # finds overridden method in SecondClass


           
       
Related examples in the same category
1.  Use __class__, __bases__ and __dict__ for sub and super class Use __class__, __bases__ and __dict__ for sub and super class
2.  Print out class tree Print out class tree
3.  Inherited method Inherited method
4.  Class inheritance: inherit member variable override function Class inheritance: inherit member variable override function
























Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.