下面代码中v1和v2调用了相同接口 move(),但输出结果不同,这体现了面向对象编程的( )特性。

ex117650 单选题 共 个子题
class Vehicle:
    def __init__(self, brand):
        self._brand = brand # 私有属性用下划线表示

    def set_brand(self, brand):
        self._brand = brand

    def get_brand(self):
        return self._brand

    def move(self):
        print(f"{self._brand} is moving...")

class Car(Vehicle):
    def __init__(self, brand, seat_count):
        super().__init__(brand)
        self._seat_count = seat_count

    def show_info(self):
        print(f"This car is a {self.get_brand()} with {self._seat_count} seats.")

    def move(self):
        print(f"{self.get_brand()} car is driving on the road!")

class Bike(Vehicle):
    def __init__(self, brand):
        super().__init__(brand)

    def move(self):
        print(f"{self.get_brand()} bike is cycling on the path!")

def main():
    v1 = Car("Toyota", 5)
    v2 = Bike("Giant")

    v1.move() # 输出: Toyota car is driving on the road!
    v2.move() # 输出: Giant bike is cycling on the path!

if __name__ == "__main__":
    main()
A

继承 (Inheritance)

B

封装 (Encapsulation)

C

多态 (Polymorphism)

D

链接 (Linking)

正在加载题目数据…
已答 /
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析
讨论
发布
登录后参与讨论 立即登录
发布讨论需先绑定并验证手机号 去绑定手机号
加载中…
我
我
回复 @
回复 @
发送
还没有人讨论,来发表第一条吧