Learn
Well done! You learned a lot very quickly, so let’s do a review:
- Inheritance is a way to avoid duplication across multiple classes.
- In inheritance, one class inherits the members of another class.
- The class that inherits is called a subclass or derived class. The other class is called a superclass or base class.
- We can access a superclass’ members using
base
. This is very useful when calling the superclass’ constructor. - We can restrict access to a superclass and its subclasses using
protected
. - We can override a superclass member using
virtual
andoverride
. - We can make a member in a superclass without defining its implementation using
abstract
. This is useful if every subclass’ implementation will be different.
Instructions
The completed code is provided for you here.
Make sure you are comfortable with inheritance before you move on from this lesson. Here are a few questions to test yourself:
- In Program.cs,
Bicycle.Describe()
is called. Find the definition for that method in theBicycle
class, then find the abstract definition of that method inVehicle
. - In Program.cs, a
Sedan
is instantiated. Find the constructor definition in theSedan
class. What happens when that constructor callsbase()
? - In Bicycle.cs,
SpeedUp()
is defined. How is it different fromSpeedUp()
in theVehicle
class?
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.