All language subtitles for 012 Copy 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

The copy constructor copies every value from one object to another.

In the previous lesson, you decided to sell a second Nissan, so you made a new object and passed in

the same values.

Now, I have to admit, passing every valley twice is a bit annoying.

In this lesson, you're going to get a copy constructor and call it.

Constructor overload means having more than one constructor.

So far, you created one constructor when you pass in for argument's, Java knows to call the constructor

with four parameters.

Now, a class can have many constructors, as many as you want, each constructor shares the same name

as the class that it's in, but it takes different parameters.

You can have a constructor with four parameters, three parameters, two parameters, one parameter

or even zero.

And the fact that each instructor has the same name, how does Javin know which one I intend to call?

Java looks at the arguments you pass, then it's going to know which constructor you want it to call.

For example, you can create a car object and pass in two arguments to the constructor.

Java's going to know to run the constructor with two parameters.

Why does this matter?

Well, we're about to add a new constructor.

And that constructor is the copy constructor, the copy constructor copies every value from one object

to another.

The copy constructor takes one parameter, the object you want to copy values from the source.

As you're creating a new car object, passing the object, you want to copy values from Jarvis's the

argument and it knows to run the copy constructor, the parameter source stores, a reference that points

to the Nissan object.

Then it copies every value from the source object into the current object.

So inside the car class, I'm going out of constructor.

Public car.

And this constructor, for it to run, it expects to receive another car object, car source.

Because of this object is going to be the source from which we update the fields of our new object.

All right, so we're going to set every field in the current object equal to a value from the source

object.

We're going to set the make of the object we just created equal to the make from the source object that

gets passed in.

We'll do the same thing for price.

Year and color.

And now we can call the copy constructor, certainly Nissan, to equal to a new object in UKAR.

And passing the original Nissan is the source object that we want to copy values from.

Reinier code.

And it works every value from the source object gets copied over into the new object.

You set Nisan to equal to a new object and passed the Nissan as an argument, Javert sees the argument

and knows to run the copy constructor.

The parameters source stores a reference that points to the Nissan object, this refers to the new object

we just created, the current object, the one that's calling the constructor and the copy constructor,

copies every field from the source object into the current object.

And in the end, Nissan, too, is equal to a copy of the Nissan object.

This is a way better solution to the reference trap in the old solution, we were using the first constructor

to create copies.

We were passing in four identical arguments.

So Jabarin in the constructor with four parameters.

This method is a bit annoying, in my opinion.

I like the copy constructor because it copies every value from a source.

This is actually the accepted way of copying objects, so we're going to update our table.

And this lesson, you added a copy constructor and used it, the copy constructor takes one parameter,

the object that you want to copy.

As you're creating a new car object, passing the object that you want to copy values from Java, the

argument, and it knows to run the copy constructor.

The parameter source is a reference that points to the Nissan object, and this refers to the new object

you just created, the current object, the one that's calling the constructor and the copy constructor,

copies every field value from the source object into the current object.

This is the best way and the accepted way to copy objects.

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