Python继承与多态,程序测试一个动物类,两个子类Dog、Cat。

Python继承和多态

def run_twice(animal):
    animal.run()
    animal.run()
    
class Animal(object):
    def run(self):
        print('Animal is running')
    #动物类

class Dog(Animal):
    def run(self):
        print('dog is Running...')
    def eat(self):
        print('Eating meat...')
    #狗类
class Cat(Animal):
    def run(self):
        print('Cat is running')
    #猫类
dog = Dog()
dog.run()
dog.eat()

cat = Cat()
cat.run()

run_twice(Dog())

读书和健身总有一个在路上

相关文章:

  • 2021-06-01
  • 2021-08-04
  • 2022-12-23
  • 2021-09-29
猜你喜欢
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
相关资源
相似解决方案