p 继承

class Animal:
    def __init__(self,name,agr,hp):
        self.name = name 
        self.agr = agr
        self.hp = hp

class Dog(Animal):
    def __init__(self,name,agr,hp,kind):
        Animal.__init__(self,name,agr,hp)
        self.kind = kind
    def bite(self,person):
        person.hp -= self.agr

class Person(Animal):
    def __init__(self,name,agr,hp,sex):
        Animal.__init__(self,name,agr,hp)
        self.sex = sex

jin = Dog('金老板',100,30,'teddy')
print(jin.__dict__)

 

posted @ 2018-10-21 14:51  为了等  阅读(102)  评论(0编辑  收藏  举报