Learning Programming Ideas
1 Packagecom.test.java.classs;2 3 /**4 * Created by Administrator on 2015/12/7.5 * Within the class, the order in which the variables are defined determines the order in which they are initialized. 6 * variables are initialized before any methods (including constructors) are called7 */8 Public classVariable {9 Public Static voidMain (string[] args) {TenHouse House =NewHouse (); One house.f (); A } - - } the - classwindow{ - PublicWindow (intN) { -System.out.println ("window-" +n); + } - } + A classhouse{ at //1 -Window W1 =NewWindow (1); - - PublicHouse () { - //4 -System.out.println ("House ()"); in //5 -W4 =NewWindow (44); to //6 +Window W2 =NewWindow (2); - } the //2 *Window W3 =NewWindow (3); $ voidf () {Panax NotoginsengSystem.out.println ("F ()"); - } the //3 +Window W4 =NewWindow (4); A the}
Results:
Window-1
Window-3
Window-4
House ()
Window-44
Window-2
F ()
Load order of Java variables