This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
static 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 ]