Completed the task just by hit and trial after reading all the comments of respected members
Is there any difference between instance and local variable ?
if I am correct this keyword is used to access the instance variable that is the local variable
can any one explain how this.age= age+20 is giving 20 as output
Under discussion
Comments (5)
- Popular
- New
- Old
You must be signed in to leave a comment
Anonymous #11263139
9 February, 19:58
I finished the task but:
System.out.println("The age in adjustAge() is " + age);
I think there is an error in codegym's solution, because it says this way, but in the conditions it says that it has to show age+20 in adjustAge:
Shouldn't the - this- also be added there?
System.out.println("The age in adjustAge() is " + this.age);
0
Gellert Varga
24 May 2020, 19:20
"Is there any difference between instance and local variable" : Yes, they are totally different.
The "this" keyword is used to access a variable of the passed object. (In other words: to access an instance-variable.)
Local variable: this is just a simple variable what you use in that method.
Please send me exactly that program, which shows the '20' output. Then i can explain it in more details.
+1
Seferi
2 June 2020, 17:51
Thanks mate. This cleared it for me.
0
Dinesh
17 January 2021, 14:31
0
Gellert Varga
18 January 2021, 19:39
+3