#继承的第一个好处:子类获得父类的所有功能
#第二个好处:多态,即父类型的方法可被子类型覆盖
class Animal(object): #父类
def run(self):
print ('Animal is running...')
class Dog(Animal): #子类,类继承
def run(self): #当子类和父类都存在相同的run()方法时,子类的run()覆盖了父类的run(),即继承的另一特征多态
print ('Dog is running...')
dog = Dog()
dog.run()#Dog is running...
def run_twice(animal):
animal.run()
animal.run()
run_twice(dog) #Dog is running... Dog is running...