首页 > 编程语言 > 详细

python中类的多态和继承

时间:2020-07-19 17:01:38      阅读:54      评论:0      收藏:0      [点我收藏+]
# -*- coding: utf-8 -*-
class Animal:

def eat(self):
print(‘Animal is eating...‘)


class Bird(Animal):

def sing(self):
print(‘Brids is singing...‘)

def eat(self):
print(‘Brid is eating...‘)


class Dog(Animal):

def laugh(self):
print(‘Dogs is laughing...‘)

#def eat(self):
#print(‘Dog is eating...‘)
pass


a = Animal()
# a.eat()
#
b = Bird()
# b.eat()
# b.sing()
#
d = Dog()
# d.eat()
# d.laugh()


def demo_eat(q):
q.eat()


for iteam in [a, b, d]:
demo_eat(iteam)

python中类的多态和继承

原文:https://www.cnblogs.com/xixirangrang/p/13339741.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!