Where are static final variables used in java? -
i studying java , wanted know what's usage of static final
variables in application designing. please provide examples too.
uses of static final
variable :
- to define compile time constant value. e.g :
integer
class defines constant calledmin_value
:public static final int min_value = 0x80000000;
- to create non modifiable reference can accessed globally : e.g singleton pattern using
public static final
reference.
when mark variable defined in class static
, shared across instances of class
. when mark variable in class final
, can initialized once either on same line declaration of variable or in constructor of class. putting both together, member static final
variable shared across instances of class
, must initialized declared, , cannot modified once declared.
Comments
Post a Comment