原理:利用静态初始化块(static initialization block )或者初始化块(Initialization Blocks)public class Hello{ static { System.out.pirntln("Hello,World!"); } System.exit(0); } /* When you invoke the class with java Hello, the class is loaded, the static initialization block prints "Hello, World," and only then do you get an ugly error message that main is not defined. You can avoid that blemish by calling System.exit(0) at the end of the static initialization block. */
转载请注明原文地址: https://ibbs.8miu.com/read-22454.html