1. Constants: Also known as final variables, can only be assigned once in the entire program
final int num = 1215;
num = 1216; //error, can only be assigned once
2. Class member variable: A variable that is not defined in a method is a member variable, and a variable defined in the method body is a local variable
Member variable meaning: object's properties
public class book{
int id;
String name; //Two member variables
Public String GetName () {
int id = 0; //Local variables, must be assigned or initialized
}
}
3.static keyword: A variable declared as static, constants and methods are statically members.
For static members, all objects share a variable, and you can use the class name. Static member in this class or other class to invoke a static member.
In a member variable, there is a static member variable, and no static adornment is an instance variable (access needs to create an object).
Pubic class statictest{
static int i = 5; //static member variable
public static void Main () {
System.out.println (STATICTEST.I); //Call static member variable
}
}
NOTE: You cannot declare a local variable in a method body as static
The This keyword cannot be used in static methods, and non-static methods cannot be called directly
(distinguishes between classes and objects: this represents a reference to the object that called the function, and the static method belongs to the class, not to the object, and the object does not necessarily exist after the static method is successfully loaded).
4. Local variables can override member variables (global variables) when they are named repeatedly with member variables, except for local variables in the loop body (distinguish the scope of each variable)
Variable, final constant, class member variable, static keyword, instance variable, static variable, local variable