//#java programming ideas P94 //Inside the class, the order in which variables are defined determines the order of initialization. Even though variable definitions are distributed among method definitions, they are still initialized before any methods (including constructors) are called. package com.ztao2333.service; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; class Window{ Window(int maker){ System.out.println("Window" + maker); } } class House{ Window w1 = new Window(1);//Before constructor House(){ // in the constructor System.out.println("House"); w3 = new Window(33);//Reinitialize w3 } Window w2 = new Window(2); //After constructor void f() { System.out.println("f"); } Window w3 = new Window(3);//end } public class test { public static void main(String[] args) { House h = new House(); h.f(); } } /* Output Window1 Window2 Window3 House Window33 f */
Initialization order of variable definitions
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326590686&siteId=291194637
Ranking