标签:
1 package fengke.hashcode; 2 /** 3 * 详细讲明了null 与new class()的区别; 4 * 分清了static与construction的运行关系; 5 * @author 锋客 6 * 7 */ 8 9 public class StacticAndConstructionTest { 10 11 public static int a = 0; 12 13 static { 14 a = 10; 15 System.out.println("父类的静态代码块在执行a=" + a); 16 } 17 18 { 19 a = 8; 20 System.out.println("父类的非静态代码块在执行a=" + a); 21 } 22 23 public StacticAndConstructionTest() { 24 this("a在父类带参构造方法中的值:" + StacticAndConstructionTest.a); // 调用另外一个构造方法 25 System.out.println(a); 26 System.out.println("父类无参构造方法在执行a=" + a); 27 } 28 29 public StacticAndConstructionTest(String n) { 30 System.out.println(n); 31 System.out.println(a); 32 33 } 34 35 public static void main(String[] args) { 36 StacticAndConstructionTest tsc = null; 37 System.out.println("new操作:"); 38 tsc = new StacticAndConstructionTest(); 39 } 40 41 }
null 与new class()的区别;static与construction
标签:
原文地址:http://www.cnblogs.com/fengke/p/4800286.html