class A {
static {
System.out.println("static output of A");
}
{
System.out.println("not static output of A");
}
public A(){
System.out.println("constructor output of A");
}
}
class B extends A {
static {
System.out.println("static output of B");
}
{
System.out.println("not static output of B");
}
public B(){
System.out.println("constructor output of B");
}
}
class C {
static {
System.out.println("static output of C");
}
{
System.out.println("not static output of C");
}
public C(){
System.out.println("constructor output of C");
}
public static void main(String[] args){
B b = new B();
System.out.println("------------------------");
B b2 = new B();
}
}
输出为:
static output of C
static output of A
static output of B
not static output of A
constructor output of A
not static output of B
constructor output of B
------------------------
not static output of A
constructor output of A
not static output of B
constructor output of B
详细解释可见以下文章:
[url]http://d-y-zh.iteye.com/blog/607027[/url]
[url]http://blog.youkuaiyun.com/superbeck/archive/2009/02/22/3920693.aspx[/url]