diff --git a/src/oop/oop1.py b/src/oop/oop1.py index b7268c5263..964e9fa2f7 100644 --- a/src/oop/oop1.py +++ b/src/oop/oop1.py @@ -17,3 +17,25 @@ # pass # # Put a comment noting which class is the base class + +#base class "Vehicle" +class Vehicle: + pass + +class FlightVehicle(Vehicle): + pass + +class Airplane(FlightVehicle): + pass + +class Starship(FlightVehicle): + pass + + +class GroundVehicle: + pass +class Car(GroundVehicle): + pass + +class Motorcycle(GroundVehicle): + pass diff --git a/src/oop/oop2.py b/src/oop/oop2.py index 29d3e481fe..f1106984cf 100644 --- a/src/oop/oop2.py +++ b/src/oop/oop2.py @@ -4,12 +4,19 @@ # object is constructed. class GroundVehicle(): - def __init__(self, num_wheels): + def __init__(self, num_wheels = 4): self.num_wheels = num_wheels + def drive(self): + return "vroooom" # TODO - +class Motorcycle(GroundVehicle): + def __init__(self, num_wheels=2): + super().__init__(num_wheels=num_wheels) + + def drive(self): + return "BRAAAP!!" # Subclass Motorcycle from GroundVehicle. # # Make it so when you instantiate a Motorcycle, it automatically sets the number @@ -26,6 +33,13 @@ def __init__(self, num_wheels): GroundVehicle(), Motorcycle(), ] +print(vehicles[0].drive()) +print(vehicles[1].drive()) +print(vehicles[2].drive()) +print(f' The number of wheels on a motorcylce is {vehicles[2].num_wheels}') +print(vehicles[3].drive()) +print(vehicles[4].drive()) + # Go through the vehicles list and print the result of calling drive() on each.