1.static member variables
- A static variable is also called a class variable, and all instances access the same variable
- static final is used to define constants, usually named with uppercase and underlined.
Packagecn.lz.base;/*** Static keywords *@authorlzzz **/ Public classJ17100803 {intID = 1; Static intIDD = 2; Public Static voidMain (string[] args) {J17100803 J1=NewJ17100803 (); J17100803 J2=NewJ17100803 (); J1.idd+ = 1; J2.idd+ = 1; J1.id+ = 1; J2.id+ = 1; System.out.println (j1.id); //2System.out.println (J1.idd);//4System.out.println (j2.id);//2System.out.println (J2.idd);//4System.out.println (J17100803.idd);//can be accessed by classname. Variable name }}2.static method
The static method of the public adornment can be accessed through the class name. Variable name
3.static Domain
- The static field is only executed once during the class load time
- {} non-static initialization code block is executed before the constructor
4. Static Import
Package cn.lz.base; Import static java.lang.math.*; /** @author*/Publicclass J17100803 { publicstaticvoid main (string[] args) { System.out.println (ABS (// } }
Java Static keyword