Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Parent class
- class Dog:
- species = 'mammal'
- def __init__(self, name, age):
- self.name = name
- self.age = age
- # Child class (inherits from Dog class)
- class RussellTerrier(Dog):
- def run(self, speed):
- return "{} runs {}".format(self.name, speed)
- # Child class (inherits from Dog class)
- class Bulldog(Dog):
- def run(self, speed):
- return "{} runs {}".format(self.name, speed)
- # Child classes inherit attributes and
- # behaviors from the parent class
- jim = Bulldog("Jim", 12)
- print(jim.name)
- # Child classes have specific attributes
- # and behaviors as well
- print(jim.run("slowly"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement