看明白下面程序就知道了。
public class Test6 {
public static void main(String[] args){
new B();
new A.C();
}
}
class A{
private P p1 = new P("A--p1");
static P p3 = new P("A--p3");
public A(){
System.out.println("A()");
}
private P p2 =new P("A--p2");
static{
new P("A--static");
}
{new P("A{...}");}
public static class C {
private P p1 = new P("C--p1");
static P p3 = new P("C--p3");
public C(){
System.out.println("C()");
}
private P p2 =new P("C--p2");
static{
new P("C--static");
}
{new P("C{...}");}
}
}
class B extends A {
private P p1 = new P("B --p1");
static P p3 = new P("B -- p3");
public B() {
System.out.println("B()");
}
public P p2 = new P("B -- p2");
static {
new P("B -- static");
}
{new P("B{...}");}
}
class P {
public P(String s) {
System.out.println(s);
}
}
结果为: