package com.example.demo;
class X{
Y y=new Y();//2,,,,4
public X(){
System.out.print("X");//5
}
}
class Y{
public Y(){
System.out.print("Y");//3,,,,7
}
}
public class Z extends X{
Y y=new Y();//6,,,,8
public Z(){
System.out.print("Z");//9
}
public static void main(String[] args) {
new Z();//1
}
}
先执行父类中的new Y
输出:YXYZ