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
In this video, we'll create the bank class, so we'll start by setting up inside Bank Java and the
bank is going to be in charge of managing accounts and transactions.
So here I'll create an array list.
Type accounts called accounts, and I'll create another ArrayList.
Not a ray array list of type transaction.
Called transactions.
Now we'll add a constructor that receives no parameters, public bank.
And here we can initialize the area list.
This accounts is equal to a new object of the ArrayList class.
That can store account objects.
Seems like going after import accounts, OK?
Then we'll set this that transactions equal to a new object of the ArrayList class that can store transaction
objects.
OK, now we need methods that we can use to add account objects to the account surrealist and transaction
object to the transactions ArrayList.
We're going to start with ad account.
So we'll see public void ad accounts.
This method receives an account object.
And to the Arab, the state accounts, we're going to add a new copy of the account object.
But wait, a second account is an abstract class.
So it doesn't matter if this is a checking savings or loan object.
We can't create a new account object.
And that's why we need a clone method, a clone method.
What it does is it returns a copy of the object that calls it so inside account counter Java.
We're going to force.
We're going to force every child the class to override Clone, so we'll say public abstract account
clone.
OK.
And now back here, we can say this state accounts don't add account cyclone.
And what that's going to do is return a copy of the object that calls it.
So if this object is checking, it's going to call the clone method from the checking class.
If this object is savings, it's going to call the clone method from the savings class.
If this object is loan, it's going to call the clone method wherever it is from the loan class.
And ultimately, Clone will return a copy of that object.
But right now, we still have to override the clone methods and each child.
So we'll start with checking.
I like to define my clone method right after the copy constructor.
So here I'll override Clone.
OK, now inside Clone, we're going to create a new checking object.
And the object we're creating, it's going to get all of its values from the current object that's calling
this method, which would be this.
We'll do the same thing inside savings.
We'll put a clone method right after the copy constructor in here, I will say return new savings.
This.
Put a clone method inside Lone.
Return a new loan object that's going to get all of its values from the current object, that's calling
this method.
All right, now, we're going to test our clone methods, so go back to the article and copy over these
objects inside mean we can remove the following?
We don't need any more.
An ad for break points.
We're getting a bunch of errors.
Not sure why.
Oh, we got to import the account class.
OK.
Let's visualize the runtime.
Here it creates a new object of the chucking class.
And now in this line, Clone is supposed to return a copy of this object.
How does it do it?
Well, let's step inside.
So Clone returns a new checking object passing in the current object as the source the copy values from.
So ultimately, that's going to call the copy constructor.
OK.
So that new object we just created that became the current object and the one that originally called
this method, that is now the source object that we're copying values from.
Here, the copper constructor is updating its ID, its name and its balance.
And now Clone returns a new copy of that object.
Perfect.
Same thing for savings.
This one is pretty simple, we're just creating a new savings object, passing in three values into
the constructor.
Nothing interesting here, but here Savings Cyclone Clone is returning a new copy of the object that
calls it so we'll step inside.
Clone creates a new savings object, passing in the current object as the source the copy values from.
So ultimately, this is calling the copy constructor.
The object we just created becomes the current object, and the object that originally called the clone
method becomes the source object to copy values from.
And here we're copying every value from the source object into the current one.
Clone returns the new object.
And we're good.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.