//父类
public class superclass {
protected int super_a;
private int super_b=9;
protected static int super_x=printstr("superclass static init super_x");
public superclass(){
system.out.println("super class constructor action.... ");
system.out.println("super_a="+super_a);
system.out.println("super_b="+super_b);
super_a=33;
}
static int printstr(string string){
system.out.println(string);
return 47;
}
}
//子类
public class subclass extends superclass{
private static int sub_b=printstr("subclass static init sub_b");
public subclass(){
system.out.println("sub class constructor action.... ");
system.out.println("sub class super_a="+super_a);
system.out.println("sub class sub_b="+sub_b);
}
}
//程序入口,执行代码
public static void main(string[] args) {
subclass subclass=new subclass();
}
###执行结果
superclass static init super_x
subclass static init sub_b
super class constructor action....
super_a=0
super_b=9
sub class constructor action....
sub class super_a=33
sub class sub_b=47