At the start of this lesson we had duplicate code in Sedan and Truck. We know that duplicated code leads to errors, so we created a superclass Vehicle to contain that code.

But one version of the duplicated code lives on in Truck! Once we have Truck inherit from Vehicle we can remove that code as well. At that point, we’ll have three classes that have Speed, LicensePlate, SlowDown(), etc. but we’ll have it written in only one place.



Make Truck inherit from Vehicle:

  • Use colon syntax to announce that Truck inherits the Vehicle class.
  • Remove the duplicated properties and methods from Truck.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?