JAVASE的static
javase的static是和类一块初始化的。
package STATIC静态; public class test { static int age; int score; public static void main(String[] args) { test.age=100;//可以直接用类名调用静态变量age test t1=new test(); t1.score=100; System.out.println(t1.age); } }
package STATIC静态; public class person { { System.out.println("匿名代码块"); } //静态代码块只执行一次 static { System.out.println("静态代码块"); } person() { System.out.println("无参构造器"); } public static void main(String[] args) { person p1 = new person(); System.out.println("========================="); person p2=new person(); } }
package STATIC静态; //静态import导入包 import static java.lang.Math.random; public class student { public static void main(String[] args) { System.out.println(random()); } }
原文:https://www.cnblogs.com/Sum-muji/p/15036639.html