Whenever you declare a variable it becomes accessible across a class.
That's only true, if this variable was declared globally. If you have something like this
-
public void myMethod()
-
{
-
int var = 3;
-
}
-
you won't be able to access
var outside of that method.
I dont think you can have a static variable for methods. You can use local variables for methods that live only inside the method. I assume that is what you are meaning by static local methods.
I think what is meant is something like this:
-
public void myMethod()
-
{
-
static int var = 3; // This is not allowed in Java
-
var++;
-
System.out.println(var);
-
}
-
where the output would be:
4
5
6
7
when called 4 times. But no, it certainly can't be done in that way and I don't think it can be done at all in Java.
Greetings,
Nepomuk