python继承和重写init方法--实例
来源:互联网 发布:阿里云节点选择 编辑:程序博客网 时间:2024/06/04 21:41
class FooParent(object): def __init__(self): self.parent = 'I\'m the parent.' print 'Parent' def bar(self,message): print message, 'from Parent' class FooChild(FooParent): def __init__(self): FooParent.__init__(self) print 'Child' def bar(self,message): FooParent.bar(self,message) print 'Child bar function.' print self.parent if __name__=='__main__': fooChild = FooChild() fooChild.bar('HelloWorld')
super继承
class FooParent(object): def __init__(self): self.parent = 'I\'m the parent.' print 'Parent' def bar(self,message): print message,'from Parent' class FooChild(FooParent): def __init__(self): super(FooChild,self).__init__() print 'Child' def bar(self,message): super(FooChild, self).bar(message) print 'Child bar fuction' print self.parent if __name__ == '__main__': fooChild = FooChild() fooChild.bar('HelloWorld')
- class Dad(object):
- def __init__(self, surname ):
- self.surname = surname
- class Son_1(Dad):
- def __init__(self, surname, name ):
- Dad.__init__(self, surname)
- self.name = name
- class Son_2(Dad):
- def __init__(self, surname):
- Dad.__init__(self, surname)
- self.name = 'Si'
- if __name__ == '__main__':
- son_1 = Son_1('Li', 'Goudan')
- print son_1.surname, son_1.name
- son_2 = Son_2('Li')
- print son_2.surname, son_2.name
0 0
- python继承和重写init方法--实例
- python继承和重写init方法
- 创建继承和方法重写
- 继承、重载、重写和子类实例化
- 重写 - init 方法总结
- 重写init方法
- python 继承重写父类方法
- python对象的继承和重写
- python对象的继承和重写
- python-对象、私有属性_方法、继承(多重继承)、重写
- EXT 笔记 构造方法,类继承,类实例方法重写
- Objective-c - 构造方法(init方法)和init方法的重写
- 继承和方法重写如何支持多态性
- 静态(static)方法的继承和重写
- 静态(static)方法的继承和重写
- 继承、方法重写和多态
- java中的继承和方法的重写
- 静态(static)方法的继承和重写
- Java微信二次开发之6-文本消息回复内容限制,如何实现乱码转码使消息体内容限制跟真实一样
- 安卓客户端 微信支付遇到的问题
- 电容与EMC-电容不同功能时对整板EMC的作用
- 集成ZXing完美适配各种机型实现扫一扫~
- IDEA 编译 JS 无法使用require()
- python继承和重写init方法--实例
- kibana 访问IP分布图
- Hbase常用命令
- org.springframework.util.Assert
- 求最大公约数及最小公倍数
- 微信支付(微信支付的坑基本上都踩过一遍了)
- 【转自官网】WURFL 浏览器版本识别API+末尾附WURFL工具包
- 【Qt开发】Qt让线程休息一段时间
- NGUI 字体相关