Created
September 9, 2013 09:42
-
-
Save fnielsen/6493552 to your computer and use it in GitHub Desktop.
Simple example of class derivation in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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