构造函数顺序

时间:2022-08-01 19:26:03
构造函数顺序构造函数顺序
 1 class X
 2 {
 3     X()
 4     {
 5         System.out.println("x");            //2
 6     }    
 7     Y y=new Y();                            //1
 8 }
 9 class Y
10 {
11 
12     Y()
13     {
14         System.out.println("y");
15     }
16 }
17  class Z extends X{
18 
19     /**
20      * @param args
21      */
22      Y y=new Y();            //3
23     Z()
24     {
25         System.out.println("z");            //4
26     }
27     public static void main(String[] args)
28     {
29         // TODO Auto-generated method stub
30         new Z();
31     }
32 
33 }
View Code