Instance variable: an instance variable if it is declared outside of the class's method code snippet and there is no qualifier static. An instance is another term for an object. Local variable: If declared within the method body of the class, it is a local variable. () static variable: If an instance variable is declared as static, it is a static variable, or a class variable.a static variable can be referenced directly after the class declaration, but the instance variable must be instantiated before it can be used. static variables are neither in the stack nor in the heap, but are placed in a static storage area. (such as the v2=0=200=400 in the book, the last V2 value is the third)static methods and classes occur at the same time,after birth can visit the first born,the class name cannot access the generic member method, nor can the member variable be accessed. Static variables can only be accessed in static methods (because they are born at the same time). By adding the keyword static before the variable declaration, you can leave the local variable with the value of calling a method multiple times. such as: v2=0=200=400, then the result of V2 is 400. static data types
- Type * Object Name
- Always store a specific data type
- The compiler checks for syntax during the encoding phase
JAVAExperiment Five(1) public class MyClass {
private float V1;
private static int v2;public static void main (string[] args) {
MyClass a=new MyClass ();
MyClass b=new MyClass ();
a.v1=100;
a.v2=200;
b.v1=300;
b.v2=400;
System.out.println ("a.v1=" +a.v1);
System.out.println ("a.v2=" +a.v2);
System.out.println ("b.v1=" +b.v1);
System.out.println ("b.v2=" +b.v2); The result: a.v1=100; a.v2=400; b.v1=300; b.v2=400;
instance, local, static variable (Java)