Gautam Joshi wrote:
Here, the difference is this.creditro is referring the instance variable value and this.getCredito() is calling a method of this object..
just understand what is happening here..
at Line no. 39 : this.credito = this.getCredito() + valorrecebido;
this.credito is refering to this instance variable, which is being assigned at this line...with the value of cerdito + valorecebido,
here, we assume that credito = 0; and valorecebido = 50 so now at the line no. 39 credito value will become 50, which is 0(zero) before the execution of this line;
at Line no. 40 : this.credito = getCredito() + valorrecebido;
Here, this.credito = 50 and will be incemented by 50.. and this .credito = 100, How??
Let's see, credito is being assigned with getCredito() + valorrecebido(), here, getCredito()
will give us a value = 50 ( because, the above line has just assined a vaue of 50 to this.credito which is first 0, check it.)
and valorrecebido value is in this scope is 50 what we assumed ,
so the ultimate value of this.credito will be 100 after the line no. 40 is being executed.
at Line no. 50 : the same thing will be repeted and the ultimate value of this.credito will become 100 + 50 = 150.