第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()
0 0