父类:
public class SuperA {
static {
System.out.println("SuperA static block");
}
int a = getA();
public SuperA(){
System.out.println("SuperA Constructor");
}
public int getA(){
System.out.println("SuperA field a init");
return 1;
}
}
子类:
public class SubA extends SuperA{
static {
System.out.println("SubA static block");
}
int b = getB();
public SubA(){
System.out.println("SubA Constructor");
}
public int getB(){
System.out.println("SubA field b init");
return 1;
}
}
驱动类:
public class FirstTest {
/**
* @param args
* note: the output messege is different somewhat.
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new SubA();
}
}