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.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database