The constructor runs as soon as you create your object.
We created a new object of the dealership class, the field is an array of car objects, as always,
every field starts off as zero or null, and it's the constructors job to update every field as soon
as we create the object.
So in this lesson, you're going to add a constructor to your dealership class.
So we can, at a dealership, instruct you in your dealership class, as always, it's going to be public,
it's going to share the same name as the class.
And for now, I'm not going to add parameters.
I know what you're thinking, we should be passing in a parameter, but I don't want to do that until
you're more comfortable working with an array of objects.
So for the time being, the constructor is going to remain incomplete.
All I want for now is for the cars failed to start off with a room for three elements and they're all
going to be empty.
Think of each element in the area as a parking space.
One by one, we're going to add car objects to each parking space.
So in the constructor, we can set the field.
Equal to a new car array with the size of three.
The requirements don't mention how many cars the dealership can hold until you're free to make the array
as big as you want.
For now, I'm choosing three.
And since the field is private and we don't have any getters, print the contents inside the constructor
print line erase.
To string.
This Dakar's.
And that's all.
When you're on the code, the first line creates an object of the dealership class.
Your brackets have no arguments, so Java runs the constructor with no parameters, the constructor
set your field equal to enumerate with the size of three and the array cars has three open spots that
we can put Khazen.
So remove the print statement.
You should only ever have field updates in a constructor.
And that's all.
In this lesson, you added a constructor.
First, you credit a dealership object.
Your brackets have no arguments, so Java runs the constructor with no parameters.
The constructor set your field equal to a new era with a size of three, and now the array has three
open spots that we can add cars to, but we don't have a way of accessing or updating the fields from
outside.
So the next step is data getter and a setter.