| Author: J Ramesh 05 Sep 2008 | Member Level: Silver | Rating: Points: 3 |
Hi Goutham,
It's a question of design. The answer lies in the purpose of your class.
If you have an utility method like java.lang.Math.max(), it's a good idea to declare that method static. This way, you don't have to instatiate an object every time just for using that method (you don't need that object anyway).
Although a static method can't access instance variables, it can access static variables. A common use of static variables is to define "constants". Examples from the Java library are Math.PI or Color.RED. They are qualified with the class name, so you know they are static. Any method, static or not, can access static variables. Instance variables can be accessed only by instance methods.
Hope this helps for more clarity check the following sites http://www.experts-exchange.com/Programming/Languages/Java/Q_20183269.html http://www.leepoint.net/notes-java/flow/methods/50static-methods.html
regards Ramesh
|