This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
An instance method requires an instance of the object to be called. The opposite of an instance method is a static method. If you use the qualifier "static" when you define a method, it is a static method instead of an instance method.
Instance methods can access instance variables and they can access static variable (also known as class variables because there is only one static variable for the entire class regardless of which instance you are using).
Static methods can only access static variable.
The most famous static method is the main() method.
Also, if you look at the API JavaDoc, the Math class is made up of all static methods. For example, if you want to calculate the square root of a primitive. There is no object, so rather than requiring you to create an object, you call:
int x = 144; Math.sqrt(x);
In the above code, instead of using an instance, you use the name of the class, "Math" because there is no instance of an object.
Again, if you leave off the static qualifier, you get an instance method as you are calling it or a regular method as Campbell is calling it.
Joined: Sep 05, 2007
Thanks. I knew it was something simple, but I just wasn't sure if there was something weird going on.