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.

[369 byte] By [kraton_mayaa] at [2007-11-27 11:29:44]
# 1

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.

TuringPesta at 2007-7-29 16:29:46 > top of Java-index,Java Essentials,New To Java...
# 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.

kraton_mayaa at 2007-7-29 16:29:46 > top of Java-index,Java Essentials,New To Java...
# 3

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;

}

TuringPesta at 2007-7-29 16:29:46 > top of Java-index,Java Essentials,New To Java...
# 4

> 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.

floundera at 2007-7-29 16:29:46 > top of Java-index,Java Essentials,New To Java...
# 5

Thanks for the snippet.

kraton_mayaa at 2007-7-29 16:29:46 > top of Java-index,Java Essentials,New To Java...