Test classes with diamond inheritance.

This commit is contained in:
Captain ALM 2022-11-30 19:37:43 +00:00
parent 5bc4e53553
commit e699ebf017
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

26
main.py
View File

@ -6,12 +6,26 @@ class Train:
self.name = name if name else "#" self.name = name if name else "#"
def __str__(self): def __str__(self):
return f"Class {self.class_}({self.name})" return f"Class {self.class_}({self.name})"
def manufacturer(self):
return ""
class C315(Train): class BREL(Train):
def __init__(self, name): def __init__(self, class_):
#Train.__init__(self, 315, name) super().__init__(class_, "")
super().__init__(315, name) def manufacturer(self):
return "BREL"
c315 = C315("Joe") class PEP(Train):
print(c315) def __init__(self, class_):
super().__init__(class_, "PEP")
def manufacturer(self):
return "Unknown"
#The presendence of definitions is the order in the inheritance bracket
class C315(BREL, PEP):
def __init__(self):
super(BREL,self).__init__(315)
c315 = C315()
print(c315, c315.manufacturer())
del c315 del c315