File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Instance methods... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Instance methods..." Watch "Instance methods..." New topic

Instance methods...

Dan Silva
Ranch Hand

Joined: Sep 05, 2007
Posts: 86
What is an instance method? Thanks.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46410
An ordinary method.
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

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;

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.
Dan Silva
Ranch Hand

Joined: Sep 05, 2007
Posts: 86
Thanks. I knew it was something simple, but I just wasn't sure if there was something weird going on.
I agree. Here's the link:
subject: Instance methods...
It's not a secret anymore!