In lạiTác giả: Vũ trụ không gianThời gian cập nhật: 2023-11-04 03:33:44254
我正在学习python,正在学习类和对象。我对此代码有疑问
class machine(object): def __init__(self,processor): print "I am in constructor of machine class" print processor
class computer(machine): def __init__(self,name,processor): print "I am in constructor of computer class" super(computer,self).__init__(processor) print name, print processor
class laptop(machine): def __init__(self,name,processor): print "I am in constructor of laptop class" super(laptop,self).__init__(processor) print name, print processor
class respbarry(computer,laptop): def __init__(self,name,processor): print "I am in constructor of respbarry class" super(respbarry,self).__init__(name,processor) print name, print processor
m = machine("P4") c = computer("Computer","P4") l = laptop("Laptop","P4") r = respbarry("Respbarry","P4")
现在做上面我得到的错误是
I am in constructor of machine class P4 I am in constructor of computer class I am in constructor of machine class P4 Computer P4 I am in constructor of laptop class I am in constructor of machine class P4 Laptop P4 I am in constructor of respbarry class I am in constructor of computer class
Tôi là một lập trình viên xuất sắc, rất giỏi!