class A(object):
def go(self):
print "go A go!"
def stop(self):
print "stop A stop!"
def pause(self):
raise Exception("Not Implemented") class B(A):
def go(self):
super(B, self).go()
print "go B go!" class C(A):
def go(self):
super(C, self).go()
print "go C go!"
def stop(self):
super(C, self).stop()
print "stop C stop!" class D(B,C):
def go(self):
super(D, self).go()
print "go D go!"
def stop(self):
super(D, self).stop()
print "stop D stop!"
def pause(self):
print "wait D wait!" class E(B,C): pass a = A()
b = B()
c = C()
d = D()
e = E() # 说明下列代码的输出结果 a.go()
b.go()
c.go()
d.go()
e.go() a.stop()
b.stop()
c.stop()
d.stop()
e.stop() a.pause()
b.pause()
c.pause()
d.pause()
e.pause()

答案

输出结果以注释的形式表示:

a.go()
# go A go! b.go()
# go A go!
# go B go! c.go()
# go A go!
# go C go! d.go()
# go A go!
# go C go!
# go B go!
# go D go! e.go()
# go A go!
# go C go!
# go B go! a.stop()
# stop A stop! b.stop()
# stop A stop! c.stop()
# stop A stop!
# stop C stop! d.stop()
# stop A stop!
# stop C stop!
# stop D stop! e.stop()
# stop A stop! a.pause()
# ... Exception: Not Implemented b.pause()
# ... Exception: Not Implemented c.pause()
# ... Exception: Not Implemented d.pause()
# wait D wait! e.pause()
# ...Exception: Not Implemented

为什么提这个问题

因为面向对象的编程真的真的很重要。不骗你。答对这道问题说明你理解了继承和Python中super函数的用法。

本文首发于Python黑洞网,博客园同步跟新

最新文章

  1. 无限循环轮播图之JS部分(原生JS)
  2. 以实际的WebGIS例子探讨Nginx的简单配置
  3. Mac OSX定位命令路径的方法
  4. perl在命令行中打印单引号
  5. Stanford机器学习---第八讲. 支持向量机SVM
  6. linux 缺少动态连接库.so--cannot open shared object file: No such file or directory
  7. Android概述(思维导图)
  8. leetcode面试准备:Triangle
  9. Eric Pement的单行awk命令收集
  10. javascript监听事件兼容
  11. jdk8预览
  12. ResultSet与Result
  13. .NET平台机器学习
  14. Chatbot思考录
  15. flex检查对象是否存在某个方法(函数)、属性的最简方法
  16. 关于NLB的群集操作模式知识 (转载)
  17. SQL学习(持续更新)
  18. Unity使用OpenGL绘制经纬线圈
  19. 决策树归纳算法之ID3
  20. Flutter学习笔记(一)

热门文章

  1. .eslintrc.js相关配置
  2. SnowFlake --- 分布式id生成算法
  3. ollvm 新增字符串加密功能
  4. CentOS使用手册(三)
  5. IntelliJ Idea 环境搭建
  6. Redis的常用功能
  7. Linux运维常用脚本整理
  8. Es学习第五课, 分词器介绍和中文分词器配置
  9. Spring 讲解(一 )
  10. 【leetcode】982. Triples with Bitwise AND Equal To Zero