A superclass is defined just like any other class:

class Vehicle { }

And a subclass inherits, or “extends”, a superclass using colon syntax (:):

class Sedan : Vehicle { }

A class can extend a superclass and implement an interface with the same syntax. Separate them with commas and make sure the superclass comes before any interfaces:

class Sedan : Vehicle, IAutomobile { }

The above code means that Sedan will inherit all the functionality of the Vehicle class, and it “promises” to implement all the functionality in the IAutomobile interface.



In Vehicle.cs, build an empty Vehicle class.


In Vehicle.cs, define:

  • string LicensePlate property (getter only)
  • double Speed property (getter and private setter)
  • int Wheels property (getter only)
  • void Honk() method
  • SpeedUp() method
  • SlowDown() method

In Sedan.cs, use colon syntax to announce that Sedan inherits the Vehicle class.


Sedan now inherits the members you defined in Vehicle. Remove them from Sedan.cs. You may still see errors and that’s okay! We’ll fix those in the next exercise.

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?