【发布时间】:2021-06-29 21:14:38
【问题描述】:
班级家长: country="印度"
def func1(self,name):
self.name=name
print("hey there")
print(name)
类子(父): 公司="宝马"
def func2(self):
print("comp=",self.Company)
print(self.name) #not working
Obj=Parent()
Obj.func1("ram")
Obj2=Child()
Obj2.func2()
【问题讨论】:
-
Obj2如果您在其上调用func1方法,则将仅具有name属性,因为该方法会创建该属性。在此之前,Obj2没有name属性 -
另外,您的代码中没有多重继承。
-
啊是啊谢谢..这是一个单一的继承
标签: python oop inheritance multiple-inheritance