jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes The Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The "static" keyword. HELP" Watch "The "static" keyword. HELP" New topic

The "static" keyword. HELP

Brian K.

Joined: Feb 04, 2002
Posts: 1
I have an exam tonight, and I just can't seem to get the concept of the "static" keyword. If someone could break it down for me nice and simply, by 5:30 est I would greatly appreciate it.
Thank you

Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

Static took me a while to figure out too... and it turns out its actually pretty simple.
Basically if you define a class as static, there is only one instance of that class. When you call a method in the class, you call it directly on the class itself, not on a particular instance of that class.
When you call a method on a static class, it looks like this:

Whereas with a non-static class, you first make an instance of that class, and then call the method on the instance.

Hope that helps a bit....

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Just the facts:
from velmurugans study guide

Can be applied to nested classes, methods, variables, free floating code-block (static initializer)
Static variables are initialized at class load time. A class has only one copy of these variables.
Static methods can access only static variables. (They have no this)
Access by class name is a recommended way to access static methods/variables.
Static initializer code is run at class load time.
Static methods may not be overridden to be non-static.
Non-static methods may not be overridden to be static.
Abstract methods may not be static.
Local variables cannot be declared as static.
Actually, static methods are not participating in the usual overriding mechanism of invoking the methods based on the class of the object at runtime. Static method binding is done at compile time, so the method to be invoked is determined by the type of reference variable rather than the actual type of the object it holds at runtime.

good luck on your test
[ February 04, 2002: Message edited by: Dave Vick ]

I agree. Here's the link: http://aspose.com/file-tools
subject: The "static" keyword. HELP
It's not a secret anymore!