On line 3 you have an instance class variable called i. That variable can be seen in all methods except when it is hidden by a local variable. On line 12 you have a local variable also called i that hides the instance class variable. Line 16 accesses the instance class variable directly. It is 3 because you use it in line 6.
[Edit: missed that the first i is static.]
All things are lawful, but not all things are profitable.
When you loop within the static main method, you don't declare a new int variable in your loop, you assign a value to one that already exists, the static one. You don't have to qualify the static variable's name with class name if you don't want to. It's a tricky piece of code. I would always qualify for readability.
So basically, it increments the static i variable and then prints out its last value.
With best regards,
Anton Golovin (firstname.lastname@example.org) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
posted 2 years ago
Thanks for the replies! I think I understand it.
You can thank my dental hygienist for my untimely aliveness. So tiny:
Create Edit Print & Convert PDF Using Free API with Java