0

issue with an inner class

why is it that the variable "id" is shown as both 1 and 5 in this code?? when I want it to show id itself it shows 1 but when I assign the same "id" variable to variable "a" it shows its initial value of 5! https://code.sololearn.com/cqHlwnZqvB3R/?ref=app

25th Feb 2021, 4:41 PM
salar vahidi
salar vahidi - avatar
3 Antworten
+ 4
Swap statements at line 4 and 5, you'll see why 👍
25th Feb 2021, 4:52 PM
Ipang
+ 3
salar vahidi When you create object of inner class in Robot constructor then id assigned value to a so here a will be 5 After creating object of the inner class, you assigned value of i to id so here id will be 1
25th Feb 2021, 4:52 PM
A͢J
A͢J - avatar
+ 2
I Am AJ ! Ipang thank you both for your help 😄
3rd Mar 2021, 2:49 AM
salar vahidi
salar vahidi - avatar