class Animal(object):
def run(self):
print('Animal is running....')
class Dog(Animal):
print('Dog is running....')
class Cat(Animal):
print('Cat is running')
class Tortoise(Animal):
print('Tortoise is running slowly....')
def runTwice(animal):
animal.run()
#不是动物类,但是有相同的run方法
class ABC(object):
print('hello,world')
an=Animal()
an1=Dog()
an2=Cat()
an3=Tortoise()
abc=ABC()
an.run()
an1.run()
an2.run()
an3.run()
abc.run()
runTwice(an)
runTwice(an1)
runTwice(an2)
runTwice(an3)
runTwice(abc)
输出。。。。。。。。。。。。。。。。。。。。
Animal is running....
Dog is running....
Cat is running
Tortoise is running slowly....
hello,world
不是动物类,但是有相同的run方法,是指相print方法?
Sign in to make a reply
用户6786697361_46373
class Animal(object):
def run(self):
print('Animal is running....')
class Dog(Animal):
def run(self):
print('Dog is running....')
class Cat(Animal):
def run(self):
print('Cat is running')
class Tortoise(Animal):
def run(self):
print('Tortoise is running slowly....')
def runTwice(animal):
animal.run()
animal.run()
#不是动物类,但是有相同的run方法
class ABC(object):
def run(self):
print('hello,world')
an=Animal()
an1=Dog()
an2=Cat()
an3=Tortoise()
abc=ABC()
an.run()
an1.run()
an2.run()
an3.run()
abc.run()
runTwice(an)
runTwice(an1)
runTwice(an2)
runTwice(an3)
runTwice(abc)
输出。。。。。。。。。。。。。。。。。。。。
Animal is running....
Dog is running....
Cat is running
Tortoise is running slowly....
hello,world
Animal is running....
Animal is running....
Dog is running....
Dog is running....
Cat is running
Cat is running
Tortoise is running slowly....
Tortoise is running slowly....
hello,world
hello,world