views:

127

answers:

2

I have been told several definitions for it, looked on Wikipedia, but as a beginner to Java I'm still not sure what it means. Anybody fluent in Java and idiot?

Thanks in advance

+11  A: 

static means that the variable or method marked as such is available at the class level. In other words, you don't need to create an instance of the class to access it.

public class Foo {
    public static void doStuff(){
        // does stuff
    }
}

So, instead of creating an instance of Foo and then calling doStuff like this:

Foo f = new Foo();
f.doStuff();

You just call the method directly against the class, like so:

Foo.doStuff();

Does that help? Please let me know if that's not clear.

Good luck!

inkedmn
That makes sense! Thanks.
Philip Strong
It should also be mentioned that a static field is shared by all instances of the class, thus all see the same value of it.
Péter Török
@Peter: it's not so much "shared by all instances" as that there's just one of it because it belongs to the class. Something `public static` is just free-for-all for everybody, not strictly just shared between instances.
polygenelubricants
+2  A: 

In very laymen terms the class is a mold and the object is the copy made with that mold. Static belong to the mold and can be accessed directly without making any copies, hence the example above

DroidIn.net