父类方法

# encoding: utf-8

class Animal(object):
    """docstring for Animal"""
    def __init__(self, name, age):
        super(Animal, self).__init__()
        print 'animal __init__'
        self.name = name
        self.age = age

    def move(self):
        print 'animal move'
        
class Cat(Animal):
    
    def __init__(self, name, age):
        super(Animal, self).__init__()
        print 'cat __init__'


    def move(self):
        super(Cat, self).move()  # 调用父类方法
        print 'cat move'


a = Animal('nn', 4)

a.move()


c = Cat('c', 5)
c.move()

猜你喜欢

转载自wzgdavid.iteye.com/blog/2203358