1 class Animal(object): 2 def __init__(self, name): 3 self.Name = name 4 5 def talk(self): 6 raise NotImplementedError("Subclass must implement abstract method") 7 8 @staticmethod 9 def animal_talk(obj): 10 obj.talk() 11 12 def __del__(self): 13 pass 14 15 16 class Cat(Animal): 17 def talk(self): 18 return 'Meow~~~~~' 19 20 21 class Dog(Animal): 22 def talk(self): 23 return 'Woof!woof!' 24 25 26 def exp(): 27 cat1 = Cat('TOm') 28 dog1 = Dog('Jone') 29 print(cat1.talk()) 30 print(dog1.talk()) 31 print(Animal.animal_talk(cat1)) 32 print(Animal.animal_talk(dog1))
执行结果:
Meow~~~~~
Woof!woof!
None
None
为什么后面两个调用没有返回值????