In English, static
In terms of method type, it corresponds to the type of "static method".
Variables that can be used without instantiating a class are called static variables.
Can be used with or without an instance. On the contrary, other than static, it cannot be used without an instance.
First, declare as follows.
Access modifier(public etc.)static type name variable name
When a variable is declared by specifying the data type, the initial value is given.
Table of initial values
Integer: 0
float:0.0f
double type:0.0d
Character type: ’\u0000′
boolean type: false
Reference type(String):null
name of the class.Variable name
Call using the class name without instantiating the class.
You can access specified methods and member variables without new.
Example:
public static String name = "";
//static method
public static String add(String , int b){
return a + b;
}
}
The above is usually called after instantiation (new), but by adding "static", it can be used without "new".
-Static variables are types of static variables and can be used without instantiation.
-On the contrary, other than that, it cannot be used unless it is instantiated.
Recommended Posts