Differences between static variables and non-static variables
Before static variablesStaticKeyword modification.
1. Memory Allocation
Static variables exist in the memory during application initialization until the end of the program running of the class in which the static variables are stored;
Non-static variables need to be instantiated before memory allocation.
2. Lifecycle
The life cycle of static variables is the application's life cycle;
The existence period of non-static variables depends on the existence period of the instantiated class.
3. Call Method
Static variables can only be passed through.Static variable name "call, class instance cannot call;
Non-static variables can be directly accessed by the instantiated class name after the class where the variable is located is instantiated.
4. Sharing Mode
Static variables are global variables shared by all class instance objects, that is, the value of static variables is changed for one instance, and those of other similar instances read the changed values;
Non-static variables are local variables and are not shared. That is, the non-static variables accessed by different instances of a class can be different values.
5. Access Method
Static members cannot access non-static members;
Non-static members can access static members.