Advertisement
amigojapan

python inheritance

Feb 10th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. #output:
  2. #flap flap
  3. #egg Layed
  4. #swimmy swimmy
  5. #walkie walkie
  6. #eww, worms
  7. #nom, nom
  8. #swimmy swimmy
  9. #swimmy swimmy
  10. #nom, nom
  11.  
  12. class Bird ():
  13.   name="wolly"
  14.   def layEgg (this):
  15.     print "egg Layed"
  16.   def walk (this):
  17.     print "walkie walkie"
  18.    
  19. def eatWorms(cls):
  20.   print("eww, worms")
  21. Bird.eatWorms = classmethod(eatWorms)
  22.  
  23. class Duck(Bird):
  24.   def fly (this):
  25.     print "flap flap"
  26.  
  27. class Penguin(Bird):
  28.   def swim (this):
  29.     print "swimmy swimmy"
  30.  
  31. duck1 = Duck()
  32. duck1.fly()
  33. duck1.layEgg()
  34.  
  35.  
  36. penguin1 = Penguin()
  37. penguin1.swim()
  38. penguin1.walk()
  39. penguin1.eatWorms()
  40. def eatFish(cls):
  41.   print(cls.name+" nom, nom")
  42. Bird.eatFish = classmethod(eatFish)
  43. penguin1.eatFish()
  44. penguin1.swim()
  45.  
  46. penguin2=Penguin()
  47. penguin2.swim()
  48.  
  49.  
  50.  
  51.  
  52. penguin2.eatFish()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement