Tuesday, December 13, 2011

What is a static method?

Static Method:
1. Static method is a method,that do not act on objects. Means we can call a static method before creating an object of a class by using class name.

2. Static methods are executed first in the program. Due to this reason only, we use static before main() method. So that main is called before creating an object.

3.You can define as many static methods as you want in a .java file. These methods are independent, except that they may refer to each other through calls. They can appear in any order in the file. 

4. Static methods will accept only static variables,these variables should be declared outside the static method. 

5. If a variable is declared as static, then it is initialized only once,even if you call n number of times of that class or function. 

6. Static variables are destroyed before termination of the main() method.