我有以下代码:
class Foo {
static { //static initializer block
System.out.print("Foo");
}
class Bar {
static { //static initializer block
System.out.print("Bar");
}
}
public static void main(String[] args) { // => This will print "FooBar" to the console
new Foo().new Bar();
}
}
public class Main {
public static void main(String[] args) { // This will print "BarFoo" to the console
new Foo().new Bar();
}
}
正如注释所说,它们将在独立调用Main方法时打印不同的结果.为什么在这种情况下Main方法的放置会影响打印到屏幕上的结果?