父类构造方法没有运行竟然就加载完了?
我的代码:
package com;
public class A {
static{
try {
new C().start();//启动另外一个线程
Thread.sleep(3000);//为了实现顺序,在这里耽搁3秒
System.out.println("A");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] a){
}
}//在这里运行
package com;
public class B{
static int a=2;
static {
System.out.println("static b");
}
public B(){
System.out.println("b");
}
}
package com;
public class C extends Thread{
static{
System.out.println("static c");
}
public void run(){
System.out.println(new B());//加载B
}
public C(){
System.out.println("c");
}
}
结果是:
static c
c
static b
b//直接加载B类和构造方法
com.B@61de33
A//然后加载类A,连A得构造方法都没有运行