2 回答
TA贡献1833条经验 获得超4个赞
您需要的是实现check调用父方法的方法:
class SmartPhone:
def __init__(self, name):
self.name = name
def check(self):
print(“The phone is working properly”)
#Write your code here
class Xiaomi(SmartPhone):
def check(self):
print(f"This is Xiaomi {self.name}")
super().check()
class Huawei(SmartPhone):
def check(self):
print(f"This is Huawei {self.name}")
super().check()
f = Xiaomi(“Redmi Note 8”)
c = Huawei(“Y9”)
f.check()
print(“=========================”)
c.check()
print(“=========================”)
TA贡献1810条经验 获得超4个赞
当重写超类的方法时,您需要调用 super。这意味着,
def check(self):
print(f"This is Xiaomi {self.name}")
super.check()
// codes for overriding
添加回答
举报