# vehicle.py
class Vehicle:
def __init__(self, make, model, year):
self.make = make # The make of the vehicle (e.g., Toyota)
self.model = model # The model of the vehicle (e.g., Corolla)
self.year = year # The year the vehicle was made (e.g., 2020)
def get_make(self):
return self.make # Get the make of the vehicle
def set_make(self, make):
self.make = make # Set the make of the vehicle
def get_model(self):
return self.model # Get the model of the vehicle
def set_model(self, model):
self.model = model # Set the model of the vehicle
def get_year(self):
return self.year # Get the year of the vehicle
def set_year(self, year):
self.year = year # Set the year of the vehicle
def drive(self):
print(f"The {self.year} {self.make} {self.model} is driving.") # Drive method
# minivan.py
class MiniVan(Vehicle):
def __init__(self, make, model, year, has_dual_sliding_doors):
super().__init__(make, model, year) # Call to the parent class constructor
self.has_dual_sliding_doors = has_dual_sliding_doors # New attribute for MiniVan
def has_dual_sliding_doors(self):
return self.has_dual_sliding_doors # Check if the minivan has dual sliding doors
def set_dual_sliding_doors(self, has_dual_sliding_doors):
self.has_dual_sliding_doors = has_dual_sliding_doors # Set the dual sliding doors attribute
def drive(self):
print(f"The {self.year} {self.make} {self.model} Minivan is driving.") # Minivan-specific drive
if self.has_dual_sliding_doors:
print("This Minivan has dual sliding doors.")
else:
print("This Minivan does not have dual sliding doors.")
# Main program to test the classes
if __name__ == '__main__':
# Create a Vehicle object
vehicle1 = Vehicle("Toyota", "Corolla", 2020)
vehicle1.drive() # Call the drive method for Vehicle
# Create a MiniVan object with dual sliding doors
minivan1 = MiniVan("Honda", "Odyssey", 2021, True)
minivan1.drive() # Call the drive method for MiniVan
# Create another MiniVan object without dual sliding doors
minivan2 = MiniVan("Chrysler", "Pacifica", 2022, False)
minivan2.drive() # Call the drive method for MiniVan
Output
The 2020 Toyota Corolla is driving.
The 2021 Honda Odyssey Minivan is driving.
This Minivan has dual sliding doors.
The 2022 Chrysler Pacifica Minivan is driving.
This Minivan does not have dual sliding doors.