码迷,mamicode.com
首页 > 其他好文 > 详细

Exercise 44b - composition

时间:2019-10-02 23:01:27      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:code   output   init   sel   elf   com   other   font   ext   

 

class Other(object):
    def override(self):
        print("OTHER override()")


    def implicity(self):
        print("OTHER implicity()")
    
    
    def altered(self):
        print("OTHER altered()")


class Child(object):
    def __init__(self):
        self.other = Other()


    def implicity(self):
        self.other.implicity()
    
    
    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.implicity()
son.override()
son.altered()

output

OTHER implicity()
CHILD override()
CHILD, BEFORE OTHER altered()
OTHER altered()
CHILD, AFTER OTHER altered()

 

2019-10-03

02:09:04

Exercise 44b - composition

标签:code   output   init   sel   elf   com   other   font   ext   

原文地址:https://www.cnblogs.com/petitherisson/p/11618490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!