标签:blog info 定义 com net 图片 detail ring str
1、 Java中静态变量只能在类主体中定义,不能在方法中定义。 静态变量属于类所有而不属于方法。
2、 静态块:用static申明,JVM加载类时执行,仅执行一次
public class Test { static int age1 = 1; static{ age1 = 10; System.out.println("这是静态代码块"); } { System.out.println("这是普通代码块"+age1); } public Test(){ System.out.println("这是构造方法"); } public void fun(){ System.out.println("这是普通方法fun"); } public static void show(){ System.out.println("这是静态方法"+age1); } public static void main(String[] args) { System.err.println("=============="); Test.show(); Test t=new Test(); t.fun(); t.fun(); } }
Java中Static执行顺序:https://blog.csdn.net/u010859650/article/details/81587738
java中静态代码执行顺序: https://www.cnblogs.com/sjxbg/p/8831346.html
Java static执行顺序:https://blog.csdn.net/ewzjs/article/details/78150198
标签:blog info 定义 com net 图片 detail ring str
原文地址:https://www.cnblogs.com/Dream2hc/p/java883134.html