public class TestStaticCon {
public static int a = 0;
static { a = 10; System.out.println("静态代码块在执行a=" + a); } { a = 8; System.out.println("非静态代码块在执行a=" + a); } public TestStaticCon() { this("a在类带参构造方法中的值:" + a); // 调用另外一个构造方法 System.out.println(a); System.out.println("类无参构造方法在执行a=" + a); } public TestStaticCon(String n) { System.out.println(n); System.out.println(a); } public static void main(String[] args) { TestStaticCon tsc = new TestStaticCon(); } }
输出:
静态代码块在执行a=10
非静态代码块在执行a=8
a在类带参构造方法中的值:10
8
8
类无参构造方法在执行a=8
为什么第三行输出是10??
当年话下
MM们
POPMUISE
UYOU
相关分类