python3(二十八)manyExten

""" 多重继承 """
__author__ = 'shaozhiqi'


# start ------------------------------------------------------
class Animal(object):
    pass


# 哺乳动物 -----------------------------------------------
class Mammal(Animal):
    def __init__(self):
        print(' 非蛋生。。。。。')


# 鸟类---------------------------------------------------------
class Bird(Animal):
    def __init__(self):
        print(' 蛋生。。。。。')


# 功能类-------------------------------------------------------
class Runnable(object):
    def run(self):
        print('Running...')


class Flyable(object):
    def fly(self):
        print('Flying...')


# 各种动物:----------------------------------------------------
# 多重继承 继承了Mammal, Runnable等
class Dog(Mammal, Runnable):
    pass


class Bat(Mammal, Flyable):  # 蝙蝠
    pass


class Parrot(Bird, Flyable):  # 鹦鹉
    pass


class Ostrich(Bird, Runnable):  # 鸵鸟
    pass


dog = Dog()  # 非蛋生。。。。。
dog.run()  # Running...

bat = Bat()  # 非蛋生。。。。。
bat.fly()  # Flying...

# MixIn混合继承(一般简单业务都是单一主线继承)
# 为了更好地看出继承关系,我们把Runnable和Flyable改为RunnableMixIn和FlyableMixIn
原文地址:https://www.cnblogs.com/shaozhiqi/p/11550563.html