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.
(1) How come static int can be accessed with the help of this? -- A static variable can be accessed via an instance or classname or even a null reference. So, the "this" here does not matter. Then, how come "this" correctly accesses the INSTANCE variable in your code?? Its because "this" always refers to the currently executing instance. And, in this case, it accesses the inherited static instance variable.
(2) And is it possible to hide the variable in the same method? -- You are defining a variable i that is local to wine(). So, it is not hiding because the static i is inherited but the i in wine() is totally a different variable, that too, a local variable. If you want to access the value of the local i, try this code: System.out.println(i); in place of your System.out.println(this.i);. It will display 20
Hope I am making sense.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com