why cant we use non static data members declared outside a static method within a static method?
+4
A:
Non static members belong to an object. A static method has no object.
If we have
class MyClass {
int member;
. . .
public static int statFunc() {
. . .
foo = member;
. . .
}
. . .
}
If we have two instances of MyClass
one where member = 1
and another where member = 2
and we call statFunc
then statFunc has no idea which value of member
to use.
deinst
2010-07-31 13:56:52
@deinst: thanks
brainless
2010-07-31 14:05:57
+1
A:
Try this, it seems you're confused by static
keyword:
http://download-llnw.oracle.com/javase/tutorial/java/javaOO/classvars.html
Nikita Rybak
2010-07-31 13:56:57