From c8823dbff4643472394a380cc88ddb4dc82937b0 Mon Sep 17 00:00:00 2001 From: bytesparallel Date: Thu, 7 Jul 2022 11:33:54 -0500 Subject: [PATCH] saving demonstrating super call 1 level up --- fleet.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fleet.py b/fleet.py index 92a0ca8..37e738e 100644 --- a/fleet.py +++ b/fleet.py @@ -87,19 +87,20 @@ Train1.displayLocomotiveCount() # Always encapsulate parent constructors into child classes to make those variables available class semi_Truck(RoadVehicle): - def __init__(self, _noOfTrailersAttached): + def __init__(self, _noOfTrailersAttached, _axlecount): self.noOfTrailersAttached = _noOfTrailersAttached - super(Vehicle.status,GroundVehicleInterface.travel()) + # super in Python returns an object representing the parent class and + super().__init__(_axlecount) # Don't modify passed in values unless absolutely necessary - def displayNoOfTrailersAttached(self): - print(self.noOfTrailersAttached) + def displaySemiAttributes(self): + print(self.noOfTrailersAttached, self.axleCount) def travel(self): print(Vehicle.status) -Semi_Truck1 = semi_Truck(f"This truck has {2} trailers attached.") +Semi_Truck1 = semi_Truck(f"This truck has {2} trailers attached", f"and {4} axles.") # Remember to be careful to check that you are running the method on an instance of the class, not on the class definition. -Semi_Truck1.displayNoOfTrailersAttached() +Semi_Truck1.displaySemiAttributes() # Next - implement abstracted methods and constructor classes. Demonstrate use of super if Python supports it. \ No newline at end of file