All language subtitles for 017 Step 1 - Constructor_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

We need to fix our constructor so that it can update every single field, the car class, it's five

fields.

So when you create an object of the car class, the object is going to define Fifield's.

However, your constructor only updates four of them.

In this lesson, you're going to fix your constructor.

Your constructor is missing a parameter, it's the constructor's job to update every field in the object,

so your constructor needs to receive another parameter string parts.

And now set the array field from the current object.

This parts is equal to a copy of the perimeter erased that copy of.

We're going to get a copy of the Pozza ray.

And how much of it do we want to copy all of it parts just like remember to avoid setting array variables

equal to each other, otherwise you'll fall into a reference trap.

We talked about this table in Module one, but it's also in your cheat sheet.

So inside main create a new array of parts, string parts.

And it's going to store two parts, Tirhas and Keese.

And the reason we have errors is because of the constructor is now expecting five parameters.

And we're only passing in four values.

So make sure to pass in the part array into each constructor call.

OK, we're good.

And before we run the code removed, the individual calls to drive the drive action is going to play

its role later.

Right now, we don't need it.

Can't run the code.

And these are not spare parts, is it?

Not anymore, but instead of printing a reference to the array we're going to use to string to print

the contents of the array arrays.

To string.

Nissan parts.

Perfect.

We're making a lot of progress.

You said Nissan equal to when you object and passed in five values, Java runs the constructor with

five parameters.

The parts parameter copies, the value inside the parts argument, the reference.

So the parts parameter and parts arguments share a reference to the same array.

Every field updates with a new value.

But notably, we set the parts field equal to a copy of the array.

Now, I need to tell you to pay attention to the reference trap, the reference trap occurs when you

mishandle arrays or objects.

What would happen if we directly set the parts field equal to the parts?

Brammer.

Let's try this out in our code test that parts equal parts.

This is dangerous.

Now, the argument.

The perimeter and field alshehri reference to the same array.

By mistake, let's assume I changed index one from the outside variable parts.

I'll change the next one and set it equal to a written.

Do you see what I mean?

I meant only update the outside variable, the argument we Pastan, but the Nissan field changed as

well.

Have a look, you said Nissan equal to a new object and passed in five values, Gever runs the constructor

with five parameters.

The parts parameter copies, the value inside the parts argument, a reference.

So the parts parameter and parts arguments, a reference to the same array, we said every field equal

to a parameter.

The party field copies the value inside the parts parameter, also a reference.

Now the argument parameter and field share a reference to the same array.

The parameter only exists inside the constructor.

So eventually it falls out of scope.

But the field and outside variables still point to the same array.

And that's why modifying the outside variable directly affected the state of my field.

With that being said, I need to warn you that the reference drop is a recipe for bugs, when many variables

reference the same thing, your application's behavior becomes unpredictable.

Your variables are going to start changing when you don't expect them to.

And you're always going to scratch your head saying what's going on?

To avoid this headache, it's really simple, it should be really careful about how you handle arrays

and objects.

I encourage you to follow my tables and pay attention to the reference Trappe.

So once again, I'm going to set the field equal to a copy of the parameter.

This time around, changing the outside variable should have no effect on the field, a straight out.

And there you go.

All right, we have to make the field private again, every field needs to be private.

The array field is no exception.

And now we have areas in Maine you cannot access a private field, and that's good, you should never

have direct access to a field.

So for now, all we can do is delete the print statements and we're going to add get her in the next

lesson.

In this lesson, you fixed your constructor, the constructor is missing a parameter, so you added

a parts parameter.

Now your constructor is all good because as soon as you create a new object, your constructor updates

every field inside of it.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.