Madbones wrote:
But I have done this before successfully (The variable is not named var.That was an example).
The name doesn't matter. What matters is that it is declared inside a method and falls out of scope as soon as program flow returns from that method (the stack frame in which it resides is obliterated, not to be recreated until the next call to your method).
Madbones wrote:
What would be the correct way?
I'm not sure of your exact circumstances, but if your object is persistent, I would just declare an instance variable for your counter in the same class where you declare that method. Instance variables maintain their value until the object in which they reside is destroyed.