A stupid "static" problem.
Sorry people. I am really new to this Java stuff.
I understand what a static method means. But my problem is that whether all items (variables, method calls) inside a static method are assumed to be static as well.
To rephrase: Can I safely say that items inside a static method are static by default?
Sorry for the trouble. Thanks in advance.
Well things scoped inside the method dont exist after the method.
But as for class variables, only static variables can be used from inside
a static method.
public class X{
public static void method(){
int x = 1; // not static or non-static
//y = 3; // WRONG
z = 4; // OK
X.z = 4; // Same as previous, also OK
}
public int y = 1;
public static int z = 2;
}
> Thanks for responding.
>
> I've read one article, but I cant remember where that
> says all items inside a static method are assumed
> static. I really cant confirm this.
>
> Thanks.
It doesn't really make sense to assume one way or the other. As TuringPest mentioned the variables inside a method (static or non-static) no longer exist once the method exits. So you cannot access those variables statically.