首页 新闻 搜索 专区 学院

Python多态问题

0
[待解决问题]
 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))
View Code

执行结果:

Meow~~~~~
Woof!woof!
None
None

 

 

为什么后面两个调用没有返回值????

淵漈的主页 淵漈 | 菜鸟二级 | 园豆:202
提问于:2018-04-24 00:06
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册