> 文档中心 > python中重写父类属性,代码分析

python中重写父类属性,代码分析

python中重写父类属性,代码分析

class Animal(object):    def eat(self): print('蛋糕')    # 公共方法    def call(self): print('哇哇叫')class Dog(Animal):    # 重写父类的call方法    def call(self): print('不叫了')class Cat(Animal):    # 重写父类的call方法    def call(self): print('叫一声')dog= Dog()dog.eat()dog.call()print('-'*40)cat = Cat()cat.eat()cat.call()

运行结果python中重写父类属性,代码分析