add abstract and extending classes
This commit is contained in:
1 parent
f2b4dbf6de
commit
3a5d654cfe
1 file changed
+52
@@ -0,0 +1,52 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
class Luftfahrzeug(ABC):
|
||||||
|
def __init__(self,Hersteller=None, Baujahr=None):
|
||||||
|
self.Hersteller = Hersteller
|
||||||
|
self.Baujahr = Baujahr
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def starten(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Flugzeug(Luftfahrzeug):
|
||||||
|
def __init__(self, Hersteller=None, Baujahr=None, Spannweite=None):
|
||||||
|
super().__init__(Hersteller, Baujahr)
|
||||||
|
self.Spannweite = Spannweite
|
||||||
|
|
||||||
|
def starten(self):
|
||||||
|
print("Das Flugzeug startet")
|
||||||
|
|
||||||
|
class Hubschrauber(Luftfahrzeug):
|
||||||
|
def __init__(self,Hersteller=None, Baujahr=None, Rotordurchmesser=None):
|
||||||
|
super().__init__(Hersteller, Baujahr)
|
||||||
|
self.Rotordurchmesser = Rotordurchmesser
|
||||||
|
|
||||||
|
def starten(self):
|
||||||
|
print("Der Hubschrauber startet")
|
||||||
|
|
||||||
|
FZ = Flugzeug(Hersteller="xyz",Spannweite=45)
|
||||||
|
HS = Hubschrauber(Baujahr=1999,Hersteller="abc",Rotordurchmesser=15)
|
||||||
|
|
||||||
|
# HS.Hersteller = "Airbus"
|
||||||
|
# HS.Baujahr = 2023
|
||||||
|
# HS.Rotordurchmesser = 10
|
||||||
|
|
||||||
|
# FZ.Hersteller = "Heinkel"
|
||||||
|
# FZ.Baujahr = 1928
|
||||||
|
# FZ.Spannweite = 15
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("Hubschrauber:")
|
||||||
|
print(f"Hersteller: {HS.Hersteller}")
|
||||||
|
print(f"Baujahr: {HS.Baujahr}")
|
||||||
|
print(f"Rotordurchmesser: {HS.Rotordurchmesser}")
|
||||||
|
HS.starten()
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("Flugzeug:")
|
||||||
|
print(f"Hersteller: {FZ.Hersteller}")
|
||||||
|
print(f"Baujahr: {FZ.Baujahr}")
|
||||||
|
print(f"Spannweite: {FZ.Spannweite}")
|
||||||
|
FZ.starten()
|
||||||
|
print()
|
||||||
Reference in new issue
Block a user