首页 > 编程语言 > 详细

Python 中的类的继承

时间:2019-05-14 16:04:12      阅读:130      评论:0      收藏:0      [点我收藏+]
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()

  

  

Python 中的类的继承

原文:https://www.cnblogs.com/conpi/p/10862636.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!