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
A class can override methods that it inherits.
Previously, you saw that the object class is the common ancestor of every class, so every class inherits
methods from the object class.
Now, clients can customize it can override methods that inherits.
So in this lesson, you're going to override the two string method.
Inside main Java, call to string from one of the objects and print the results again, we haven't defined
a two string method inside the person class.
So where is the two string coming from?
Remember that the object class is the ancestor of every single class.
So by default, our person class is going to inherit this two string method.
So let's use it and see what happens.
Run the debugger.
And here it basically returns the identity of the object, the name of the class, followed by an ad
symbol and he hexadecimal representation of the object has code.
So back here, if I press next.
It shows us what we expect the name of the class, followed by the add symbol and the objects code as
a hexadecimal string.
OK, now, instead of printing the hexadecimal, it would be nice if printing the object print its fields'.
That's why we need to override the two string method override means to change the logic of an inherited
method.
You're going to customize you're going to override the two string method for the person class and you
already know how to override a tutoring method.
You've done it a million times before.
All we have to do is replicate the signature of the two string method we're inheriting.
And here we can write whatever we want.
We could return high.
But the point is we overrode the two string method and Java is going to use this one instead.
So try it out, run the debugger.
And it calls the tutoring method that we overrode.
But there's a much easier way to override to string, just right to string and let Intellisense autocomplete
the method for you and beautiful once again, don't worry about super will cover it later.
And now we can just customise the two string method just like we always do.
We'll just return the objects fields as part of a long string.
And now remember, the override annotation just means we're overriding a method that we inherited.
You don't have to include it.
In the past, we never had it.
But it's good practice to leave it because if you misspell the method, it's going to throw an error
and say there's no method string whity to override.
So just leaving it as good practice, it's going to prevent potential errors.
Now, if we rerun the code to the person, object calls the overwritten it to string method.
And it prints our fields.
But recall, we don't need to explicitly call the tutoring method when you print an object java smart
enough to internally call it.
Let's recap, you overrode the two Tshering method.
To override means to change the logic of an inherited method when you override a method, Java calls
that one instead.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.