Adding to this point ,In java we have two types of methods,
1. instance methods
Static methods can't use any instance variables. The this keyword can't be used in a static methods. You can find it difficult to understand when to use a static method and when not to use. If you have a better understanding of the instance methods and static methods then you can know where to use instance method and static method.
Ben Ooms wrote:A static block is executed at class loading and a static method when its called.
See this example:
When the Bar main is executed class Foo is loaded at line 12 and produce:
static block called when line 13 is executed static method of Foo is called and produce:
static method called
Subhash Pavuskar wrote:. . . The this keyword can't be used in a static methods. . . .
Nor can the keyword super.
Nice post there
You can find it difficult to understand when to use a static method and when not to use.
Try searching for “Campbell Ritchie classification of methods” and you find this. Click the link and it will give hints about when methods might well be static.
A static method does not require use read or investigate any information about an object (of the same class). A static method does not record write alter or manipulate any information about an object (of the same class).