Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- SimpleSample: Class 2
- '''
- class Vehicle(object):
- # Init value of main class (only color)
- def __init__(self, color):
- self._color = color
- # Print color
- def color(self):
- print("Vehicle color is {color}".format(color=self._color))
- # Print details
- # By default there won't be any tires :(
- def details(self):
- print("Vehicle color is {color} but I have no tires"\
- .format(color=self._color))
- class Car(Vehicle):
- # Init values of Car class (tires and color)
- # Note super!
- def __init__(self, tires, color):
- super(Car, self).__init__(color)
- self._tires = tires
- # Print the details
- # Override the "main" classes details function and print
- # with number of tires :-)
- def details(self):
- print("My car is nice. It is coloured as {color} and it have {tires} tires"\
- .format(color=self._color, tires=self._tires))
- myCar = Car(4, "red")
- myCar.color()
- myCar.details()
- notCar = Vehicle("blue")
- notCar.color()
- notCar.details()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement