Advertisement
Guest User

Cloud101 Introduction to python's inheritance

a guest
Mar 4th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. class Animal(object):
  3.     '''
  4.    Our animal object
  5.    '''
  6.  
  7.  
  8.     def __init__(self,name,animalType):
  9.         print "My name is ",name
  10.         print "I am a ",animalType
  11.        
  12.     def testM__private(self):
  13.         print 'blaat'
  14.    
  15.     def makeNoise(self,noise):
  16.         print noise
  17.        
  18.     def sleep(self):
  19.         print "zzzzZZZZzzzzZZZ"
  20.        
  21.     def eat(self,food):
  22.         print "Eating ",food
  23.        
  24. class Tiger(Animal):
  25.  
  26.     def __init__(self,name):
  27.         super(Tiger,self).__init__(name,"Tiger")
  28.         self.makeNoise("roar")
  29.  
  30.     def stalk(self):
  31.         print "Stalking an antilope"
  32.         self.eat("antilope meat")
  33.  
  34. tony = Tiger("Tony")
  35. tony.stalk()
  36. tony.sleep()
  37.        
  38.        
  39. class Peacock(Animal):
  40.     def __init__(self,name):
  41.         super(Peacock,self).__init__(name,"Peacock")
  42.         self.makeNoise('CRIOOOUUUUUULLLL')
  43.        
  44.     def showTailFeathers(self):
  45.         print "Look at them feathers"
  46.    
  47.     def eat(self):
  48.         super(Peacock,self).eat("Wheat")
  49.         print "burp"
  50.        
  51.        
  52. class Fly(object):
  53.         def __init__(self):
  54.             print "I have the ability to fly!"
  55.            
  56.         def fly(self):
  57.             print "Im flying wiieeeeee"
  58.  
  59. class Swim(object):
  60.         def __init__(self):
  61.             print "I have the ability to swim!"
  62.            
  63.         def swim(self):
  64.             print "Im swimming like a boss"
  65. class Duck(Animal,Fly,Swim):
  66.         def __init__(self,name):
  67.             super(Duck,self).__init__(name,"Duck")
  68.             Swim.__init__(self)
  69.             Fly.__init__(self)
  70.                
  71. class WalkOnLand(object):
  72.         def __init__(self):
  73.             print 'I can walk on land'
  74.            
  75.         def walk(self):
  76.             print "walking... and I hope you like walking too"
  77.            
  78. class Amphibian(Animal,Swim,WalkOnLand):
  79.         def __init__(self,name,typeA):
  80.             print "Im an amphibian,"
  81.             super(Amphibian,self).__init__(name,typeA)
  82.             Swim.__init__(self)
  83.             WalkOnLand.__init__(self)
  84.            
  85. class Frog(Amphibian):
  86.     def __init__(self,name):
  87.             super(Frog,self).__init__(name,"Frog")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement