All > Technology > Programming > Java
A
static
variable defined inside a class body. Such a variable belongs to the class as a whole, and is, therefore, shared by all objects of the class. A class variable might be used to define the default value of an instance variable, for example, and would probably also be defined asfinal
, too. They are also used to contain dynamic information that is shared between all instances of a class. For instance the next account number to be allocated in a bank account class. Care must be taken to ensure that access to shared information, such as this, issynchronized
where multiple threads could be involved. Class variables are also used to give names to application-wide values or objects since they may be accessed directly via their containing class name rather than an instance of the class.- Browse Related Terms: Attribute, class constant, class variable, constant, encapsulation, instance variable, local variable, magic number, method variable, model-view pattern, out of scope, overloading, static field, static variable, this, variable
Also listed in:
- All > Technology > Programming > Perl