Advertisement
Guest User

Children's primer on OOP

a guest
Mar 19th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. class Bird(object):
  2.     MOVES = 'moving'
  3.  
  4.     def __init__(self, name):
  5.         self.name = name
  6.  
  7.     def moveTo(self, destination):
  8.         print self.name, 'is', self.MOVES, 'to', destination
  9.  
  10. class FlyBird(Bird):
  11.     MOVES = 'flying'
  12.  
  13. class Parrot(FlyBird):
  14.     def __init__(self, name, says):
  15.         FlyBird.__init__(self, name)
  16.         self.whatToSay = says
  17.  
  18.     def speak(self):
  19.         print self.whatToSay
  20.  
  21. class Ostrich(Bird):
  22.     MOVES = 'runing like only ostrichs do'
  23.  
  24. polly = Parrot('Polly', 'Polly want cookie!')
  25. polly.moveTo('Costa Rica')
  26. polly.speak()
  27. bruno = Ostrich('Buno')
  28. bruno.moveTo('his nest')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement