6.10 OOP constructor and challenge
Hello in this course we will continue on the exercises of Bank part the continuation we will see of other aspect ... of the builder in the previous course we managed to create the builder and to put the arguments that need ... we will display the values of the arguments that we put in our builder to do it we will de ... comment the line 21 account getName will allow us to display the name of the account the name of the user for example ... it will say that made the arguments that we put in the builder will put in day the fields we ... will go into account the fields we put, that is to say the number the balance the phone number the email and ... the name the arguments we passed in our builder our builder here so we call account getName we will ... display the name of the user part example we will compile and in our terminal, we have the name of the user ... username of course, we can also display the name of the account account get Numero and also if we mail ... share example where we will put the balance instead the mail and there, we will compile our program in the ... terminal, we will have the name the number the account the balance and the mail the number the balance which ... has 300 the balance it is at 300 at the beginning builder but since we were adding and called ... our getSolde before having added we will have 300 but if we came here we will have a balance at 400 ... we will compile the program balance it is 400 there the balance it is 400 here user balance ... there, we can well differentiate user balance 400 I just made a mistake here, it is user and not use ... in the previous course I mentioned that we can have several constructors we call it the overload in java the overload ... constructor allows a class to have more than one constructor have different argument list so we can have ... several builders but the arguments will be different what we can do for example, is to call a constructor in a ... other constructor so let’s return to our account class say if we empty constructor are called in other thermal years no ... parameter like our constructor here that has no parameter we want can be created an object with some value ... default then in this kind of scenario if the empty constructor is called we want to call the constructor with ... its parameters that means the constructor with the parameter number balance number phone email and name so we want ... put default share values for its 5 fields so to do this it’s simple you just type the ... keyword this in the constructor you want to call and you worker the semicolon parentheses and there in ... the parenthesis you go to put all the values you have in the constructor with parameter, that is to say the number the ... balance the telephone number the mail and the name and of course follow the orders we will start from ... put the number 1234 part example the balance 300 and if you use intellji as IDE you see that at the top ... you see well what you had to put the number the phone number balance the mail and the name ... so following this order you will not make mistakes the phone number the mail and then the name ... you will rarely use this concept-there, but you have to understand what we’re trying to do here is that ... during the creation of an object if you use the constructor without parameter the parameters that will use these are the ... parameters that we put here so if you come created an object from this manufacturer-there we will have ... parameters of the second constructor and of course will be values part default and if you come to use ... this concept one day you have to be very careful to call it from the constructor must be first so from the ... creation of our constructor this this this must to the first one cannot put other stuff part example put constructor ... without parameter in can not put this it will not work and it is an error the call of the constructor must always ... are in the front row and the stuff you put must come Then we’re gonna go back in our hand and... called the constructor without parameter to see if it functions correctly so here, we have our method with parameter, we ... will put in comment or rather we delete it and create another account object we will call the constructor ... without argument and there, we will compile and there as you see the two constructors we were called constructor with ... parameter and constructor without parameter we will return here constructor without constructor parameter with parameter and values in the ... terminal the name Johnny the number of account and the mail are exactly the same as the values we put in ... our this here Johnny and the mail john@ outlook now that any function correctly we can have fun generating ... has created another constructor and you can also generate a constructor by leaving in generete constructor we will generate ... a constructor for the mail and the name there, you have your builder and in this builder being given that we ... does not have the number and balance and the phone number we can call our builder with in argument the number ... 1234567 decimal point balance 36 part example the number then the email we have here, we’ll put the email to ... finish the name and the if we go back to the terminal, we can call our constructor this constructor to do ... that we just have the name we will put a string of character the default number just to differentiate so ... there in our hand we will create another account object account01 equal to new Account and there we will ... pass to parameter we will put in argument the mail and the name so the name the mail first after ... you put the good name @gmail and the name and there, we are going to file the email so count 01 getMail ... we are going to put in a mail variable equal to sout email and bine on you could put directly compte01.getEmail in ... the sout in the print and the you boyais bob@ gmail on peut aussi appelle le nom compile nous avons ... le mail plus the name now I’m going to put you the challenge we’re doing and in the next course we’re going to... fix the challenge here is the smoothing challenge and in the next course we’re going to fix this challenge See you soon.