Static (keyword)

In programming languages such as C, C++, Objective-C, and Java,   is a reserved word controlling both lifetime (as a static variable) and visibility (depending on linkage). The effect of the keyword varies depending on the details of the specific programming language.

C and C++
In C and C++, the effect of the  keyword depends on where the declaration occurs.

may act as a storage class (not to be confused with classes in object-oriented programming), as can,   and   (which are also reserved words). Every variable and function has one of these storage classes; if a declaration does not specify the storage class, a context-dependent default is used:
 * for all top-level declarations in a source file,
 * for variables declared in function bodies.

In these languages, the term "static variable" has two meanings which are easy to confuse: Variables with storage class, which include variables declared at top level without an explicit storage class, are   in the first meaning but not the second.
 * 1) A variable with the same lifetime as the program, as described above (language-independent); or
 * 2) (C-family-specific) A variable declared with storage class.

Static global variable
A variable declared as  at the top level of a source file (outside any function definitions) is only visible throughout that file ("file scope", also known as "internal linkage"). In this usage, the keyword  is known as an "access specifier".

Static function
Similarly, a static function – a function declared as  at the top level of a source file (outside any class definitions) – is only visible throughout that file ("file scope", also known as "internal linkage").

Static local variables
Variables declared as  inside a function are statically allocated, thus keep their memory location throughout all program execution, while having the same scope of visibility as automatic local variables (  and  ), meaning they remain local to the function. Hence whatever values the function puts into its static local variables during one call will still be present when the function is called again.

Static member variables
In C++, member variables declared as  inside class definitions are class variables (shared between all class instances, as opposed to instance variables).

Static member function
Similarly, a static member function – a member function declared as  inside a class definition – is meant to be relevant to all instances of a class rather than any specific instance. A member function declared as  can be called without instantiating the class.

Java
This keyword  means that this method is now a class method; it will be called through class name rather than through an object.

A static method is normally called as, whereas an instance method is normally called as.