Skip to content

Instantly share code, notes, and snippets.

@fnielsen
Created September 9, 2013 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fnielsen/6493552 to your computer and use it in GitHub Desktop.
Save fnielsen/6493552 to your computer and use it in GitHub Desktop.
Simple example of class derivation in Python
class Vehicle():
def is_movable(self): return True
class Car(Vehicle):
def __init__(self, color): self.color = color
def has_wheels(self): return True
class CrashedCar(Car):
# overloading the grandparent 'is_movable' method
def is_movable(self): return False
my_car = CrashedCar('silvergray')
my_car.has_wheels()
my_car.is_movable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment