Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
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.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.