, ,

In C, Java and PHP, the keyword static can be applied either to static methods or static variables. While there are subtle differences, the following applies to all three languages.

A static method can be called directly, without first creating an explicit object reference first. This is very handy for the singleton pattern, where you want one and only one instance of an object.

A static variable retains it value, even after the method ends. This is very handy for counter variables that increase each time the method is called.