//---------------------------------------------------------------------------
//-------------------------------程序开始--------------------------------
//---------------------------------------------------------------------------
public class Test {
public static void main(String[] args) {
Subclass sb = new Subclass();
}
}
class Sssuper {
int i = -1; // for debug can delete
static {
System.out.println(1);
}
Sssuper(int i) {
System.out.println(i);
this.i = i; // for debug can delete
}
}
class Subclass extends Sssuper implements Interface {
static {
System.out.println(2);
}
Sssuper su = new Sssuper(4);
Subclass() {
super(3);
//System.out.println(su1.i+1); // for debug can delete
new Sssuper(5);
}
}
interface Interface {
static Sssuper su1 = new Sssuper(0);
}
//---------------------------------------------------------------------------
//-------------------------------程序结束--------------------------------
//---------------------------------------------------------------------------
运行结论:
根据测试结果,得知在接口Interface中的实例su1并不会在运行时加载,当把//System.out.println(su1.i+1);
// for debug can delete 放开后su1才开始加载.这个例子可以帮助我们很好地理解“接口、继承,静态块之间的运行关系”。