Now that we've got a better idea of how fields work inside of a class, let's discuss how they work
when we are dealing with inheritance as we are with our class car down here.
I'm going to uncommon everything in the bottom half this file right here, and as soon as I do, you'll
notice we get an air around the new car call right here.
So here's the issue.
Our class car extends vehicle.
Any time we create an instance of something that is a vehicle, we have to provide it a color or a string
to use as the color.
So the reason we're seeing this air right here is that we have to pass in a string that will serve as
the color.
So we could fix up this air by putting a string in like red like so.
And as soon as we do that, the air goes away.
I want to show you something interesting right now, our class card does not have a constructor function.
That means that whenever we try to create an instance of car, typescript is going to automatically
call the constructor in the parent function right here.
So even though you don't see any reference to it, whenever we create this car right here, the constructor
in the parent is being called for us automatically.
And that's why we have to pass in that string.
Things are going to be just a little bit different if we define the constructor inside of class car
as well.
So let's try that right now, I'm going to define the constructor function inside of car, and I'm going
to say that this thing is going to have its own property like, let's say, public wheels.
And this will be maybe like the number of wheels that a car has.
So I'm going to annotate with the type of number like so.
Now, as soon as I define this constructor, you'll notice Nasti Air inside of here, and if I hover
over it, it says that the derived class must contain a super cool.
The word super right here is a reference to these super class or the parent class of car, which is
vehicle.
So whenever we called a constructor of a child class, we are required to call the constructor method
of the parent as well to do so, all we have to do is call super like so.
As soon as we do so, we're still going to see an air here, so super right here is a reference to the
constructor method in the parent.
And once again, the constructor and the parent wants us to pass in a string so we can make this go
away once again by putting in some hard coded string like so.
But chances are we don't want to do that.
Chances are we want to have the color still come in as an argument to our car when we create it.
So maybe we should take in a second argument to the constructor function.
That will call color, and it's supposed to be a string like so.
Notice how I did not put the public key word on here I didn't put public on because we do not want to
reassign or create a new field in car of color.
The field color belongs to vehicle.
So that's why I did not put on the modifier of public.
So now when we call the parent class constructor through these supercool right here, we're not going
to pass into hardcoded red.
Instead, we can pass in the color.
If we now go back down to the bottom of the file once more, you'll see we've got an area down here
again.
So now we are saying that our constructor for car has to be given a number of wheels as the first argument
and a second argument of a string so we can fix up this error by putting in four wheels as the first
argument.
Now, the second argument is going to be a string, which is going to pass on through the constructor
right here into the parent constructor of vehicle.
And that's pretty much it.
Now, I know we're going through this stuff really quickly.
The reason we're going through it so quickly is that basically all the projects we're going to work
on in this course are 100 percent focused on using classes to represent logic inside of application.
So really, I'm just showing you all this class stuff right now to get you used to some of the very
basic syntax.
And we're going to really repeat all these different rules that we're going over in great detail throughout
all these applications we go through.
So hopefully you're just absorbing a little bit of the syntax here.
That's really the only expectation I have.
Now, having said all that, this is really all we wanted to learn about classes, so we've taken a
look at Method's constructor's basic inheritance, super calls modifiers.
That's pretty much it, the whole ball game.
So let's have a quick pause right here.
We're going to do a wrap up on classes in the next video, and we'll start working on some really interesting
applications.
So I'll see you in just a minute.