Teil 6 "Objekte ist neu
Repository aufgeräumt.
This commit is contained in:
34
teil6/vererbung.py
Normal file
34
teil6/vererbung.py
Normal file
@@ -0,0 +1,34 @@
|
||||
class Fahrzeug:
|
||||
def __init__(self, marke, modell, farbe):
|
||||
self.marke = marke
|
||||
self.modell = modell
|
||||
self.farbe = farbe
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.marke} {self.modell} {self.farbe})'
|
||||
|
||||
#Klasse Auto erbt von Fahrzeug
|
||||
class Auto(Fahrzeug):
|
||||
def __init__(self, marke, modell, farbe, ps):
|
||||
super().__init__(marke, modell, farbe)
|
||||
self.ps = ps
|
||||
|
||||
def __str__(self):
|
||||
return f'{super().__str__()} mit {self.ps} PS'
|
||||
|
||||
#Klasse Fahhrad erbt von Fahrzeug
|
||||
class Fahrrad(Fahrzeug):
|
||||
def __init__(self, marke, modell, farbe):
|
||||
super().__init__(marke, modell, farbe)
|
||||
|
||||
def __str__(self):
|
||||
return super().__str__()
|
||||
|
||||
|
||||
bond = Auto('Aston Martin','DB5','grau','286')
|
||||
mcfly = Auto('Delorean', 'DMC-12','grau','132')
|
||||
eliot = Fahrrad('Kuwahara','ET-1','weiß')
|
||||
|
||||
print(str(bond))
|
||||
print(str(mcfly))
|
||||
print(str(eliot))
|
Reference in New Issue
Block a user