第44个python程序:类的合成
来源:互联网 发布:linux下的telnet 编辑:程序博客网 时间:2024/05/22 06:46
[root@mysql1 pshell]# cat ex44-4.py
#!/usr/bin/env Python
#-*-coding:utf-8-*-
class other(object):
def override(self):
print "other override()"
def implicit(self):
print "other implicit()"
def altered(self):
print "other altered()"
class child(object):
def __init__(self):
self.other=other()
def implicit(self):
self.other.implicit()
def override(self):
print "child override()"
def altered(self):
print "child, before other altered()"
self.other.altered()
print "child, after other altered()"
son=child()
son.implicit()
son.override()
son.altered()
[root@mysql1 pshell]# python ex44-4.py
other implicit()
child override()
child, before other altered()
other altered()
child, after other altered()
#!/usr/bin/env Python
#-*-coding:utf-8-*-
class other(object):
def override(self):
print "other override()"
def implicit(self):
print "other implicit()"
def altered(self):
print "other altered()"
class child(object):
def __init__(self):
self.other=other()
def implicit(self):
self.other.implicit()
def override(self):
print "child override()"
def altered(self):
print "child, before other altered()"
self.other.altered()
print "child, after other altered()"
son=child()
son.implicit()
son.override()
son.altered()
[root@mysql1 pshell]# python ex44-4.py
other implicit()
child override()
child, before other altered()
other altered()
child, after other altered()
0 0
- 第44个python程序:类的合成
- 第44个python程序:类的继承(隐式)
- 第40个python程序:类
- 第41个python程序1:类
- 第43个python程序:类
- 第44个python程序:类的继承(显示覆写)
- 第44个python程序:类的继承(在运行前和后覆写)
- 第25个python程序
- 输出前n个数组合成的第k个数
- 第38个python程序:列表的操作
- 第1个python程序:打印
- 第2个python程序:注释#
- 第4个python程序:变量
- 第5个python程序:变量2
- 第7个python程序:打印
- 第8个python程序:还是打印
- 第10个python程序:转义
- 第11个python程序:接收输入
- 性能监测工具 dstat
- Java内存模型&JVM参数
- lua源码剖析(一)
- C、C++、python、Java、php、C#六种语言连接mysql数据库代码
- Oracle 权限详解
- 第44个python程序:类的合成
- centos 6.5安装caffe(cpu模式)
- Java实现算法导论中图的广度优先搜索(BFS)和深度优先搜索(DFS)
- 标准模板库2(STL)——迭代器
- oracle 数据库常用指令总结
- 蘑菇街 App 的组件化之路·续
- 栈的链表实现
- 分享Kali Linux 2016.2第41周镜像虚拟机
- 汇编基础知识学习