W3School TIY Editor

  • W3School 在线教程
  • 改变方向
  • 暗黑模式
​x
 
class Car:
  def __init__(self, brand, model):
    self.brand = brand
    self.model = model
​
  def move(self):
    print("驾驶!")
​
class Boat:
  def __init__(self, brand, model):
    self.brand = brand
    self.model = model
​
  def move(self):
    print("航行!")
​
class Plane:
  def __init__(self, brand, model):
    self.brand = brand
    self.model = model
​
  def move(self):
    print("飞行!")
​
car1 = Car("福特", "野马")       # 创建 Car 对象
boat1 = Boat("伊比沙", "Touring 20") # 创建 Boat 对象
plane1 = Plane("波音", "747")     # 创建 Plane 对象
​
for x in (car1, boat1, plane1):
  x.move()