python中类的多态和继承

# -*- 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)
posted @ 2020-07-19 15:02  IOstreamIO  阅读(143)  评论(0)    收藏  举报