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's the first thing that runs as soon as you create a new object.
So it should be the one to update the fields of a newly created object.
In this lesson, you're going to fix your constructor.
Right now, we're calling the Senate to update the cars field, remove it.
Because when you create a new object, it's the constructor's job to update every field.
The dealership only has one field, so the constructor needs to receive one parameter.
An array of car objects and instead of a fixed length of three, the field is going to share the same
length as the parameter that gets passed in.
All right, so back in Maine, you need to pass in one argument that wage Albino's to call the constructor
with one parameter.
And the argument we're going to pass on is the cars are Ray.
And before testing the code, I'm going to add two more cars to the array being Pastan.
It's going to be a Honda.
Worth 7000 made in 2019.
A color of orange, and it's going to come with the standard tires and filter.
The last car is going to be a Mercedes worth twelve thousand.
Made in 2015, color of black.
And it's going to come with tires, filters, and that's put in a transmission.
All right.
And feel free to add as many car objects as you'd like, but I'm going to go ahead and print the dealership
object.
All right, there are five spots in the cars field and all of them are empty.
This makes sense because so far we're only set the length of the Crisfield, we still have an updated
every element, so every element along the array is going to be no.
OK, so the next step is to update every element in the cars filled with an object from the car's parameter.
So create a fault that runs through the length of the car's perimeter.
We can use the fawry shortcut and it creates a far loop that runs through the length of the nearest
array.
And now the cars field and cars parameter share the same length.
So using this for a loop, it can index every element in the car's field.
And at this point, careful not to fall into the reference trap.
Said every element in the cars field equal to a new car object.
In each new car, object is going to copy its values from a source and this source is going to be the
object that we're indexing from the car's parameter.
And that's it, you're ready to run your code.
And that's perfect.
There are five spots in the cars field and the constructor sets every element in the cars field equal
to an object from the car's parameter.
Why not use a raise a copy of.
You should not use a raised copy of for an array of objects.
A radar copy of Shallow Copy is the reference from every element.
So elements from both arrays are going to share a reference to the same object.
In other words, this would be the same thing as writing this.
Which means would be falling into a trap to.
Instead, use a loop that deep copies the object from every element.
So be careful, a, that copy of is going to shallow copy the reference of every element.
However, the loop deep copies the object from every element.
In this lesson, you fix the dealership constructor.
At first we were using the center to update the newly created dealership object, but when you create
a new object, it's the constructors job to run and update your fields.
In this case, the constructor sets every element in the car's field equal to an object from the car's
parameter.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.