作业
#8.初始化一个type属性表示动物种类,cry属性表示叫声
定义一个介绍函数info,打印:我是xxx,我的叫声是yyy
class Animal(object):
def __init__(self,type,cry):
self.type = type
self.cry = cry
def info(self):
print("我是{},我的叫声是{}".format(self.type,self.cry))
#9.编写鸟类Bird,猫类Cat,狗类Dog,它们都继承Animal类,初始化种类分别为'bird'、'cat'、'dog',叫声分别为'jiji','meow','wang'
class Brid(Animal):
def __init__(self):
super().__init__('brid','jiji')
#10.分别创建一个鸟,猫,狗对象,调用它们的介绍函数
b = Brid()
b.info()
#11.编写燕子类,继承鸟类,添加一个属性:子类型(subtype)。燕子的子类型为'swallow'。
重写燕子的介绍函数,打印:我是xxx,属于yyy,我的叫声是zzz,其中xxx是子类型,yyy是类型,zzz是叫声
class swallow(Brid):
def __init__(self):
super().__init__()
self.subtype = 'swallow'
def info(self):
print('我是{},我的叫声是{}'.format(self.subtype,self.type,self.cry))