继承和多态:
继承:
根据已有的类,定义新的类
继承的目的:代码重用,多态
调用父类方法:父类.方法名(self);super(子类名,self).方法名()
多重继承:
class A(object): def __init__(self): pass def sayHi(self): print ‘in A‘ class B(A): def sayHi(self): #A.sayHi(self) super(B,self).sayHi() print ‘in B‘ class C(A): def sayHi(self): super(C,self).sayHi() print ‘in C‘ class D(B,C): pass 菱形继承问题:经典类:深度优先新式类:广度优先
时间: 2024-10-13 12:05:18