Python继承和多态
发布时间:2020-12-20 10:27:41 所属栏目:Python 来源:网络整理
导读:Python继承与多态,程序测试一个动物类,两个子类Dog、Cat。 def run_twice(animal): animal.run() animal.run() class Animal(object): run(self): print ( ‘ Animal is running ‘ ) # 动物类 Dog(Animal): dog is Running... eat(self): Eating meat...
Python继承与多态,程序测试一个动物类,两个子类Dog、Cat。 def run_twice(animal): animal.run() animal.run() class Animal(object): run(self): print(‘Animal is running‘) #动物类 Dog(Animal): dog is Running... eat(self): Eating meat...狗类 Cat(Animal): Cat is running猫类 dog = Dog() dog.run() dog.eat() cat = Cat() cat.run() run_twice(Dog()) 读书和健身总有一个在路上 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |