单选题 适中
#5605

运行以下Python代码,结果是?( ) class Parent ( ) : def __init__ ( self , name ) : self . na…

运行以下Python代码,结果是?(   )

class Parent():
    def __init__(self, name):
        self.name = name
    
    def greetings(self):
        print("Parent: Hi, I'm", self.name)
    
class Child(Parent):
    def greetings(self):
        super().greetings()  
        print("Child: Hello!")
parent = Parent("Alice")
child = Child("Bob")
chilgreetings()
未登录也能判分,登录后才会记录
答案与解析
正确答案:B
解析

代码中,定义了一个Parent类和一个Child类,Child类继承自Parent类。Child类中的greetings方法使用super()函数调用了父类Parent的方法,并在其基础上添加了额外的逻辑print("Child: Hello!")。