Class inherited : Class Inheritance : Class PYTHON examples


PYTHON examples » Class » Class Inheritance »

 

Class inherited


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


           
         
  



Leave a Comment / Note


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


PYTHON examples

 Navioo Class
» Class Inheritance