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
1 changed files with 20 additions and 6 deletions

26
main.py
View File

@ -6,12 +6,26 @@ class Train:
self.name = name if name else "#"
def __str__(self):
return f"Class {self.class_}({self.name})"
def manufacturer(self):
return ""
class C315(Train):
def __init__(self, name):
#Train.__init__(self, 315, name)
super().__init__(315, name)
class BREL(Train):
def __init__(self, class_):
super().__init__(class_, "")
def manufacturer(self):
return "BREL"
c315 = C315("Joe")
print(c315)
class PEP(Train):
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