Class/Static Variables
Class/Static Variables
// salary variable is a private static variable
private static double salary;
// DEPARTMENT is a constant
public static final String DEPARTMENT = "Development "; - Are declared with the static keyword in a class, but outside a method, constructor or a block.
- There would only be one copy of each class variable per class, regardless of how many objects are created from it.
- Are stored in the static memory. It is rare to use static variables other than declared final and used as either public or private constants.
- Are rarely used other than being declared as constants.
- Are created when the program starts and destroyed when the program stops.
- Visibility is similar to instance variables. However, most static variables are declared public since they must be available for users of the class.
- Can be accessed by calling with the class name ClassName.VariableName.
Semantic portal