Originally posted by Srinivas Kalvala: Can any one type the difference between the normal object methods and static methods? mostly in problem oriented direction.
I don't know exactly what you really want to know..
But ok let me try..
Difference Between Static Method & Normal Methods
>< Instance methods are associated with an object and use the instance variables of that object. This is the default.
>< Static methods use no instance variables of any object of the class they are defined in. If you define a method to be static, you will be given a rude message by the compiler if you try to access any instance variables. You can access static variables, but except for constants, this is unusual. Static methods typically take all they data from parameters and compute something from those parameters, with no reference to variables. This is typical of methods which do some kind of generic calculation. A good example of this are the many utility methods in the predefined Math class.
With Normal Method if you need to invoke them then you have to create an Object of Class and then need to call the method with that Object.
But in Case of Static Methods you may directly call method with refernce of Class Directly.
This is the biggest use of Static methods.
There are so many built-in API's in so many classes which are declared as static so that we may directly call without instantiating the Class.
Hope this helps you..
If still any concern then revert me with exact concerns...
The Best way to predict your future is to create it - Every great individual common man
There is no problem with static methods as such. Sometimes it's necessary to call methods of a class if no instance of that class is available, or if it doesn't make sense to specify a particular instance. That's when you'd use them.
If you wish to avoid having static methods for some reason, simply don't declare any (by leaving out the "static" in their declaration). Then they become instance methods.
One serious problem with static methods is that using them significantly reduces testability, since they can't be mocked in any simple way. As Ulf noted, there are situations when they are useful, but IMO they should be avoided as far as possible.
Admit nothing. Blame everyone. Be bitter.
Look ma! I'm selling my stuff!
how do I do my own kindle-like thing - without amazon