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 that we get an ear around the new car called right here.
So here's the issue our class car extends Vehicle.
Anytime 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 area here is that we have to pass in a string that will serve as the
color so we could fix up this area 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 car 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 gonna 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 side 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 it's going to annotate with the type
of number like so as soon as I define this constructor.
You'll notice nasty air inside of here.
And if I hover over it it says that the derived class must contain a super.
Call the word super right here is a reference to these superclass or the parent class of car which is
vehicle so whenever we call the 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 error here.
So super right here is a reference to the constructor method in the parent.
And once again the constructor in the parent wants us to pass in a string so we can make this go away
once again by putting in some hardcoded 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 we'll 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 super call right here we're not going
to pass in a hard coded red.
Instead we could pass on the color if we now go back down to the bottom of the file once more you'll
see it we've got an error 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 area 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 class 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 methods constructors basic inheritance super calls modifiers.
That's pretty much it the whole ballgame.
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.