>>> class Vehicle:
def move(self):
print('我是交通工具,我能移动')
>>> class Train(Vehicle):
def track(slef):
print('我可以在轨道上高速行驶')
>>> class Automobile(Vehicle):
def tire(self):
print('我是汽车,我有轮胎')
>>> class Aircraft(Vehicle):
def wing(self):
print('我有翅膀,我会飞')
>>> class Car(Automobile):
def __init__(self, color):
self.color = color
def manned(self):
print('我是客车,只能载客')
>>> class Truck(Automobile):
def van(self):
print('我是卡车,可以载货')
>>> class AircraftCar(Aircraft, Car):
def __init__(self, color):
super(AircraftCar, self).__init__(color)
>>> train = Train()
>>> train.move()
我是交通工具,我能移动
>>> train.track()
我可以在轨道上高速行驶
>>> ab = Automobile()
>>> ab.move()
我是交通工具,我能移动
>>> ab.tire()
我是汽车,我有轮胎
>>> plane = Aircraft()
>>> plane.move()
我是交通工具,我能移动
>>> plane.wing()
我有翅膀,我会飞
>>> car = Car('red')
>>> car.move()
我是交通工具,我能移动
>>> car.tire()
我是汽车,我有轮胎
>>> car.manned()
我是客车,只能载客
>>> t = Truck()
>>> t.move()
我是交通工具,我能移动
>>> t.tire()
我是汽车,我有轮胎
>>> t.van()
我是卡车,可以载货
>>> ac = AircraftCar('red')
>>> ac.move()
我是交通工具,我能移动
>>> ac.tire()
我是汽车,我有轮胎
>>> ac.wing()
我有翅膀,我会飞
>>> ac.manned()
我是客车,只能载客
>>> ac.color
'red'
谢谢
这四题答案是啥