go语言interface接口继承多态示例及定义解析
287
2022-09-03
python之理解super及MRO列表 ( 示例版 )(python中的super())
例子 1:
class A0: def pri(self): super().pri() print("A0")class A1(A0): def pri(self): super().pri() print("A1")class B0: def pri(self): print("B0")class B1(B0): def pri(self): super().pri() print("B1")class X(A1, B1): def pri(self): super().pri() print("X")x=X()x.pri()print(x.__class__.mro())
输出:
例子 2:
class A0: def pri(self): #super().pri() print("A0")class A1(A0): def pri(self): super().pri() print("A1")class B0: def pri(self): print("B0")class B1(B0): def pri(self): super().pri() print("B1")class X(A1, B1): def pri(self): super().pri() print("X")x=X()x.pri()print(x.__class__.mro())
输出:
例子 3:
class A0: def pri(self): #super().pri() print("A0")class B0: def pri(self): super().pri() print("B0")class B1(B0): def pri(self): super().pri() print("B1")class X(B1, A0): def pri(self): super().pri() print("X")x=X()x.pri()print(x.__class__.mro())
输出:
例子 4:
class A0: def pri(self): #super().pri() print("A0")class B0: def pri(self): #super().pri() print("B0")class B1(B0): def pri(self): super().pri() print("B1")class X(B1, A0): def pri(self): super().pri() print("X")x=X()x.pri()print(x.__class__.mro())
输出:
例子 5:
class A0: def pri(self): super().pri() print("A0")class B0: def pri(self): super().pri() print("B0")class B1(B0): def pri(self): super().pri() print("B1")class X(B1, A0): def pri(self): super().pri() print("X")x=X()print(x.__class__.mro())x.pri()
(A0类中执行pri函数时候调用父类object中的pri函数,由于object类中没有pri函数所以报错)
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~