Why cant a static method declare a static variable

public static void get() {static int i=0; // This is not allowed}
[86 byte] By [relaxedgalaxya] at [2007-11-27 7:48:29]
# 1
"static" variable in a method does not have true meaning i guess
calvino_inda at 2007-7-12 19:29:21 > top of Java-index,Java Essentials,Java Programming...
# 2

In some language (like C++) you can declare a static variable in a method (whether static or otherwise).

The variable is effectively defined at class level, but hidden outside of the method.

This feature was not incorporated into Java, Probably because it doesn't really help, and makes code harder to follow.

malcolmmca at 2007-7-12 19:29:21 > top of Java-index,Java Essentials,Java Programming...
# 3
No method, whether static or non-static, can declare a member variable. Static/non-staticness only applies to members, not to local variables.
jverda at 2007-7-12 19:29:21 > top of Java-index,Java Essentials,Java Programming...
# 4

The closest you can come to that in Java is:

class C {

private static int i=0; // This is allowed

public static void get() {

}

}

Hippolytea at 2007-7-12 19:29:21 > top of Java-index,Java Essentials,Java Programming...