- [Instructor] Constructors are part
of the syntax of a class.
If you don't include one, one will be generated for you.
Also you can only do one constructor per class,
otherwise there will be a syntax error thrown at you.
But what are constructors exactly?
They are a method that creates an object
when a new instance of the class is created,
and whatever values you pass to the new instance
will be initialized inside of this object.
In simple terms, the constructor builds
our initial object for us.
For example, when we create the new cx5 instance
of the class car, we pass the values 4, v6, and gray.
The constructor of the class then builds a new object
and assigned the values to doors, engine, and color.
This is what the constructor does.
In our example we also pass values as we create
the new instance of the car class,
but we could also assign default values
without passing anything and we'll explore this next.
Also when we work with classes we can use the keyword super,
which allows to call the methods of a parent class.
If we create a new class called SUV
we could use the keyword super to call the carStats method
of the car class.
So now that we've got some basics on these items,
let's explore them in code over the next few videos.