public class Student {
public Student(String name){
System.out.println(name);
}
}
// 父类
public class FuClass {
private static Student student=new Student("父类静态变量");
private Student student1=new Student("父类非静态变量");
static {
System.out.println("父类静态代码块");
}
public FuClass(){
System.out.println("父类构造方法");
}
}
//子类
//子类
public class ZiClass extends FuClass {
private Student student=new Student("子类非静态变量");
private static Student student1=new Student("子类静态变量");
public ZiClass(){
System.out.println("子类构造方法");
}
static {
System.out.println("子类静态代码块");
}
}
//测试类代码
public class test {
public static void main(String[] args) {
ZiClass zi=new ZiClass();
}
}
最终的执行结果
<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Monaco;">父类静态变量</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Monaco;">父类静态代码块</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Monaco;">子类静态变量</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Monaco;">子类静态代码块</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Monaco;">父类非静态变量</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Monaco;">父类构造方法</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Monaco;">子类非静态变量</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; line-height: normal; font-family: Monaco;">子类构造方法</p><div>
</div>