首页 > 编程语言 > 详细

python 类的继承

时间:2021-09-13 12:13:29      阅读:21      评论:0      收藏:0      [点我收藏+]
class Ctc(object):
	def __init__(self):
		self.name = "shun"
	def run(self):
		self.prea()
		self.a()
		self.b()
		self.c()
	def a(self):
		print("a")
	def b(self):
		print("b")
	def prea(self):
		print("Prea")

class TestInstance(Ctc):
	def __init__(self):
		self.name = "shun2"
	def a(self):
		print("aa")
	def b(self):
		print("bb")

class Another(TestInstance):
	def __init__(self):
		self.name = "another"
	def a(self):
		print("aa in Another")
	# def b(self):
	# 	print("bb in Another")
	def d(self):
		print("d in Another")

class Case(Another):
	def __init__(self):
		self.name = "shun3"
	def c(self):
		print("cc in case")
	# def b(self):
	# 	print("bbb")
	# def run(self):
	# 	print("run in case")

if __name__ == ‘__main__‘:
	test = Case()
	exit(test.run())

  类的继承,会先找最底层的类是否有此函数,在找最接接近的类,直到最上层父类,就近原则

python 类的继承

原文:https://www.cnblogs.com/shunguo/p/15260249.html

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