posted 16 years ago
As your definiation in method wine(), variable int i is a local varialbe. In a method, local variable's priority is higher than instance variable(static int i), so method int i override static int i. So no matter where your code try to do somthing to variable i after you declear local variable, and your action is on the local i but not static i.
You asked how to do something to static i but not local i with method wine(). It's simple. Remember static is a conception just belongs to CLASS. What you need to do is explicity tell JVM, I want to use "Honley.i", then JVM will understand what you mean is do something to static int i. Of course you could use "this.i" instead of "Honley.i" with the same meaning. Although static variable doesn't have this reference, but JVM still under stand what do you want to.
By the way, you could even make your example code more funny by changing the code order in method like this:
Notice that "i=10" after "int i = 20". At this time, "i=10" change the value of local int i but not static int because you have already decleared local int. But this.i(static int) still remeains 99. And the output will be 99.
I consider myselft as computer scientist.