Python 中的类的继承

class parent(object):
def override1(self):
print("Parent") class child(parent):
def override2(self):
print("Child") dad=parent()
son=child() dad.override1() son.override1() son.override2()

输出结果:

Parent
Parent
Child
class parent(object):
def altered(self):
print("Parent altered()") class child(parent):
def altered(self):
print("Child,Before Parent altered()")
super(child,self).altered()
print("Child,After Parent altered()") dad=parent()
son=child() dad.altered()
son.altered()

运行结果:

Parent altered()
Child,Before Parent altered()
Parent altered()
Child,After Parent altered()

  

  

上一篇:51单片机学习笔记(郭天祥版)(6)——键盘的作业题、AD、DA、DS18B20(这里之后看清翔的补一下好了)


下一篇:python2中的__new__与__init__,新式类和经典类-乾颐堂