Cannot prevent automatic initialization, it will occur before the constructor is called.
The order in which the variables are defined determines the order in which they are initialized, even if the definition of the variable is scattered between the method definitions, it will still be initialized before any method, including the constructor.
Import static net.mindview.util.print.*;//when the constructor are called to create a//Window object and you'll see a messag E:class window { window (int marker) {print ("window (" + marker + ")");}} Class House { window w1 = new Window (1),//before constructor house () { //Show that we ' re in the constructor : print ("house ()"); W3 = new Window (33); Reinitialize W3 } window w2 = new Window (2),//after constructor void F () {print ("F ()");} Window W3 = new window (3); At End}public class Orderofinitialization {public static void Main (string[] args) {House H = new House ();
H.F (); Shows that construction was done }}//Output:window (1) window (2) window (3) House () window (+) F ()
The visible initialization operation is in the first place.
Static data initialization, see the following code
Import static Thinkinginjava. Print.*;class Go { static string s1 = "Run"; static string s2, s3; s tatic { //static block or static sentence Child (first executed, and only once, pay attention to the output) no.1 s2 = "Drive Car";  S3 = "Fly Plane"; print ("S2 & S3 Initialized"); } static void How () { print (S1 + "or" + s2 + "or" + S3);  &N Bsp } go () {print ("Go ()");} }public class Explicitstaticex { public static void Main (string[] args) { & nbsp print ("Inside Main ()"); no.4 go.how ();//no.5 print ("GO.S1:" + GO.S1);//no.6  &NBsp; } static Go g1 = new Go (); no.2 static Go g2 = new Go ();//no.3}Output
S2 & S3 Initialized
Go ()
Go ()
Inside Main ()
Run or drive car or fly plane
Go.s1:run
If the initialization operation outside the main method is not static, i.e. no static, then these two sentences will not be executed. After adding the static, they will be executed before the main method and will only be initialized once.
Constructors can be thought of as static methods.
Constructor initialization _02