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())
类的继承,会先找最底层的类是否有此函数,在找最接接近的类,直到最上层父类,就近原则