Test classes with diamond inheritance.
This commit is contained in:
parent
5bc4e53553
commit
e699ebf017
26
main.py
26
main.py
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user