I know that in C, when the keyword static
is used on a local variable, it causes that variable to remain initialized between function calls (i.e. when the variable goes out of scope). For example:
int myFunction() {
static int i = 3;
i++;
return i;
}
If myFunction()
is called twice, it will return 4 the first time and 5 the second time (because i
keeps its value between the two calls rather than being reinitialized the second time).
My question is this: does Java have an equivalent keyword to static
in C? Java also has the keyword static
, but it is used completely differently than in C.