Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
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
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 next step is to add a setter.
Every field needs a center, the parts field, it's private, yet it doesn't have one.
This means we have no way of updating it from outside.
So in this lesson, we're going to add a setter for the parts field.
We need to add a setter, because right now we have no way of updating the parts array, so inside the
car class at the very bottom, make sure the center is public.
Is lower camel case, it's going to start with the word set and end with the field name, it's going
to accept a parameter string parts.
And using a raised copy of set the parts field of the current object equal to a copy of the parameter.
And we're going to copy the full length of its elements.
All right, now, back in May, instead of spare keys, let's say the second Nissan comes with a spare
filter, but instead of creating another variable, I'm going to call this setar.
And I'm going to directly pass in a new string array.
With two elements.
Tires and filter.
By the way, this is the syntax we use to directly pass in an array without having to store it in a
variable.
It's also the same syntax that you would use to directly return an array once again without having to
store it in a variable first.
I showed you the syntax during the tic tac toe challenge, and it was also in your cheat sheet of module
one, but in case you missed it, I also included the syntax in the current cheat sheet.
Anyways, we can run the code.
And perfect, our getters and setters are working as they should.
The object calls the center passing in an array, Gever runs set parts, which receives the array as
a parameter.
The center sets the parts field equal to a copy of the parts parameter.
And because this works, we're done updating the big three.
Every field is protected by the private keyword, and the getters protect each field as well by returning
a copy of it, and the setters allow us to update each field without having direct access to it.
In this lesson, you added a setter and finally we're done fixing stuff.
Every time you add a new field, you need to update the big three, namely the constructors getters
and setters.
You started by fixing your constructor and now it updates every field when it runs.
You added another Geter, and now you can safely access any of the Fifield's.
And then you added another setar.
Now you can update any of the Fifield's, there is nothing else to fix.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.