面向对象之继承与派生

例1:非菱形继承,经典类与新式类的属性查找顺序都一样
# class E:
#     # def test(self):
#     #     print('from E')
#     pass
#
# class F:
#     def test(self):
#         print('from F')
#
#
# class B(E):
#     # def test(self):
#     #     print('from B')
#     pass
#
# class C(F):
#     def test(self):
#         print('from C')
#
#
# class D:
#     def test(self):
#         print('from D')
#
#
# class A(B, C, D):
#     # def test(self):
#     #     print('from A')
#     pass
#
# obj=A()
# obj.test()
# 例2:菱形继承
class G(object): # 在python2中,未继承object的类及其子类,都是经典类
    # def test(self):
    #     print('from G')
    pass
class E(G):
    # def test(self):
    #     print('from E')
    pass
class F(G):
    # def test(self):
    #     print('from F')
    pass
class B(E):
    # def test(self):
    #     print('from B')
    pass
class C(F):
    # def test(self):
    #     print('from C')
    pass
class D(G):
    # def test(self):
    #     print('from D')
    pass
class A(B,C,D):
    # def test(self):
    #     print('from A')
    pass
# obj=A()
# obj.test()
print(A.mro())
posted @ 2020-08-16 10:35  Οo白麒麟оΟ  阅读(119)  评论(0编辑  收藏  举报