class A{
public String context=test();
public static int num=getNum();
{
System.out.print(\"A3\");
}
static{
System.out.print(\"A1,\");
}
public A(){
System.out.print(\"A2,\");
}
public String test()
{
String str=\"A.test(),\";
System.out.print(str);
return str;
}
public static int getNum()//它只屬於A
{
System.out.print(\"A.getNum(),\");
return 11;
}
}
class B extends A{
{
System.out.print(\"c\");
}
static{
System.out.print(\"a,\");
}
public B(){
System.out.print(\"b,\");
}
public String test()//覆蓋
{
String str=\"B.test(),\";
System.out.print(str);
return str;
}
public static int getNum()//它只屬於B,不能覆蓋
{
System.out.print(\"B.getNum(),\");
return 21;
}
}
public class InitTest{
public static void main(String[] ars){
new B(); //執行到此處,結果: A.getNum(),A1,a,B.test(),A3A2,cb, [Page]
System.out.println();
new B(); //執行到此處,結果: B.test(),A3A2,cb,
}
}