What are static variables?
static variables, also called global variables, are pieces of data that are not associated with a specific example of the class. Only one value for these variables can exist regardless of the number of class objects created. Depending on the context, the static variables may be either more flexible or more restrictive than their instances of variable counterparts that have their own discrete values for each specific class object. In programming languages focused on object, good programming practice usually dictates that the use of static objects, methods or variables is kept to a minimum but have useful applications. Any assignment to the variable rewrite the previous and any information in the previous value is lost. No more data can be saved without multiple copies of the variable. If the value is changed, any object that affects must work with a new value, and if the old value should not be deleted, the change may prove harmful to each instance of the object of a particular class.If the variable is not locked in some way in formation, the risk of unexpected changes and subsequent chaos that could cause objects will cause some programmers from preventing static variables whenever possible.
static variables can sometimes be considered flexible for the same reason that they can be called restrictive. Although the value of the variable is not locked, the planned changes in its value can have positive effects. A variable that is shared between all class objects is guaranteed and can be used inside and outside the class with certainty that its value is always the same. The variables that are static have a number of useful applications, especially in the maintenance of Constants and the implementation of serialization. In particular, Java relies very much on this static serialization mechanism.
There are certain general rules that programmers often use to implement static variables. These variables usuallyThey work best as small data values, as large static objects can make the program much more rigid than it must be. Small data values can be changed quickly and easily without much fear of introducing errors. Large static objects require more time and change effort and are also more susceptible to introducing an error that would disrupt all class objects. These are instructions, not unbreakable rules, and depending on the program, there may be use for both small and large variables,