Tag: style static tracking post ACK member time static class
variables in Java are broadly divided into two broad categories: member variables and local variables.
member variables:
variables defined inside the class body are called member variables.
assume that the member variable has a static keyword adornment. The member variable is called the
Static Variables or
class Variables.
assuming that the member variable does not have a static keyword adornment, the member variable is called
non-static variables or
instance Variable.
Local Variables:
Parameters defined within the method, variables defined in the code block, are local variables.
class variables ( static variables )
1. Ability to forward reference
2. Variables belong to the class itself
3. Class variables do not depend on instances of classes, and class variables are allocated only once in the stack memory at initialization time. No matter how many instances of the class are created. No longer allocates space for class variables
4. Access class variables by using an arbitrary instance of the class, and the underlying will turn it into a class variable through the class itself. They have the same effect.
5. Once the value of the class variable has been changed, access the class variable through a random instance of the class or class, and the resulting value will be changed .
6. Will initialize before initialization of the class
instance variable (non-static variable)
1. Cannot forward reference, assuming forward reference, is called illegal forward reference, this is not agreed
2. The variable belongs to the instance object of the class
3. Allocating memory space as instances of classes are created
non-static code block
code that is wrapped directly by {}. Called non-static code block
Static code block
code that is wrapped directly by static {}, called a static code block
initialization time for class variables (static variables), instance variables (non-static variables), static code blocks, non-static blocks of code
A static keyword, such as a class variable [static variable], static code block, is initialized before the class is initialized to create an instance object, and is sequentially run from top to bottom.
initialization without static keyword modifiers (e.g., instance variables [non-static variables], non-static blocks of code) is actually extracted into the constructor of the class and is run, but it is compared to the class constructor
code blocks first run to. It is also run sequentially from top to bottom.
Java Basics-Variables are you out of your coma?