Java class object static member variables, static code blocks load execution order.
Package com.yjm.pro;import java.io.ioexception;import java.util.properties;public class Pro { public static String url; public static String username; public static string password; public static string classforname; public static string log; public static properties PROPERTIES; STATIC {  SYSTEM.OUT.PRINTLN ("Class static code block Execute test ...."); Properties = new properties (); try { properties.load ( Pro.class.getResourceAsStream ("pro.properties")); url = properties.getproperty ("url "); username = properties.getproperty (" username "); password = properties.getproperty ("password"); log = properties.getproperty ("Log"); classforname = propertiEs .getproperty ("Classforname"); } catch (IOException e ) { e.printstacktrace (); } }}
Test code
public static void Main (string[] args) {//test1 (); Test2 (); Test3 (); Test4 (); } private static void Test4 () {System.out.println (pro.class); SYSTEM.OUT.PRINTLN ("Class static variable" + Pro.log); }
Execution results
Class Com.yjm.pro.Pro
Class static code block executes test ....
Class static Variable Yes
Test class static data that executes static code blocks only when the class is referenced.
Java static member variable, static code block execution test