python | 面向对象 | 继承
2018-01-28 20:48
281 查看
# encoding: utf-8 import abc # ************************************************继承************************************************ # 1 继承的三种形态: # 单继承 # 无重叠的多继承(资源访问顺序按遵循单调性) # 有重叠的多继承 # 2 ************************************************ # super # 沿着MRO链条,找到下一级方法,调用对应的方法 class D: def __init__(self): print("d") class C(D): def __init__(self): super(C, self).__init__() print("c") class B(D): def __init__(self): super(B, self).__init__() print("b") class A(B, C): def __init__(self): super(A, self).__init__() print("a") A() # 3 ************************************************ # 抽象类 class Animal(metaclass=abc.ABCMeta): @abc.abstractmethod def call(self): pass @abc.abstractclassmethod def test(cls): pass class Dog(Animal): def call(self): print("wang wang wang") @classmethod def test(cls): print(cls.__dict__) class Cat(Animal): def call(self): print("miao miao miao") @classmethod def test(cls): print(cls.__dict__) d = Dog() c = Cat() c.call() d.call()
相关文章推荐
- Python面向对象之继承和组合用法实例分析
- python面向对象--封装,继承,多态
- Python3 与 C# 面向对象之~继承与多态
- python面向对象的继承
- Python面向对象——多重继承
- Python面向对象——多重继承大揭秘
- python 面向对象(三)多继承
- Python一天入门16:面向对象的编程3-继承
- Python-面向对象 (二 继承)
- 6.4Python面向对象(4):类的继承
- python面向对象---03-继承、多继承、super
- python语法学习面向对象之继承
- python面向对象的继承
- python面向对象(三)之继承
- python 面向对象之继承与派生
- python中面向对象--封装、继承、多态
- python-面向对象之继承
- python 面向对象 继承
- Python面向对象之继承
- Python面向对象(一):继承,多态