Riju21

33_inheritence

May 12th, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. class Vehicle():
  2.     def __init__(self, vehicleType, weight, seats):
  3.         self.vehicleType = vehicleType
  4.         self.weight = weight
  5.         self.seats = seats
  6.    
  7.     def showInfo(self):
  8.         print('type: {}, weight(in ton): {}, seat number: {} '.format(self.vehicleType, self.weight, self.seats))
  9.    
  10. class Car(Vehicle):
  11.     def __init__(self, vehicleType, weight, seats):
  12.         self.vehicleType = vehicleType
  13.         self.weight = weight
  14.         self.seats = seats
  15.  
  16. class Bike(Vehicle):
  17.     def __init__(self, vehicleType, weight, seats):
  18.         self.vehicleType = vehicleType
  19.         self.weight = weight
  20.         self.seats = seats
  21.  
  22.  
  23. c = Car('car', 200, 10)
  24. b = Bike('bike', 50, 3)
  25.  
  26. allVehicles = [c, b]
  27.  
  28. for i in allVehicles:
  29.     i.showInfo()
Add Comment
Please, Sign In to add comment