python面向对象的继承
来源:互联网 发布:linux 驱动 培训 编辑:程序博客网 时间:2024/04/24 05:34
没什么可说的,继承主要就是继承父类的一些方法,代码中很详细
#!/usr/bin/env python #coding:utf-8class Father(object):#新式类 def __init__(self): self.name='Liu' self.FamilyName='Yan' def Lee(self): print '我是父类函数Lee' def Allen(self): print "我是父类函数Allen" class Son(Father): def __init__(self): #Father.__init__(self) #经典类执行父类构造函数 super(Son,self).__init__() #新式类执行父类构造函数 self.name='Feng' def Aswill(self): #子类新增函数 print 'Son.Bar' def Lee(self):#重写父类函数Lee print '子类重写了父类函数Lee' s1=Son()print "继承了父类的姓"+ s1.FamilyNameprint "重写了父类的名字",s1.names1.Lee() #子类重写了父类函数Lees1.Allen() #子类继承了父类函数Allen
继承多个类时的顺序,经典类继承是深度优先,是一个BUG, 新式类是广度优先,应该是用新式类去定义类
新式类
class A(object): #新式类的写法 def __init__(self): print 'This is from A' def test(self): print 'This is test from A'class B(A): def __init__(self): print "This is from B" class C(A): def __init__(self): print "This is from C" def test(self): print "This is test from C" class D(B,C): def __init__(self): print 'this is D' T1=D()T1.test()
经典类
class A: def __init__(self): print 'This is from A' def test(self): print 'This is test from A'class B(A): def __init__(self): print "This is from B" class C(A): def __init__(self): print "This is from C" def test(self): print "This is test from C" class D(B,C): def __init__(self): print 'this is D' T1=D()T1.test()
0 0
- python面向对象的继承
- python 面向对象 继承
- python 面向对象继承
- Python-面向对象 (二 继承)
- Python面向对象之继承
- Python面向对象,子类,继承
- Python一天入门16:面向对象的编程3-继承
- python面向对象编程基础II(类的继承)
- Python面向对象之类的定义与继承
- python语法学习面向对象之继承
- python语法学习面向对象之继承
- Python 面向对象 —— 多重继承
- Python(十三)面向对象 -继承、多态
- Python 面向对象、继承部分、正则表达式
- Python 高阶 面向对象 继承
- 3、python面向对象之继承
- python面向对象(三)之继承
- 面向对象----类的继承
- Matlab Intro - Image Filter Sobel
- swift常用的宏
- hdu5037(贪心)
- JAVE amr转换mp3
- mysql备份还原数据库,ubuntu
- python面向对象的继承
- C++游戏之创建第一个窗体程序(一)
- 第一周 项目二:长方柱类
- 完整java开发中JDBC连接数据库代码和步骤
- P27 5
- zookeeper资料
- Linux 命令行解析之getopt方法详解
- Java的运行原理
- R6010 -abort() has been called错误分析及其解决方法