- class Single
- {
- private static Single s = new Single();
-
- private Single(){}
-
- {
- System.out.println("a");
- }
-
- static
- {
- System.out.println("b");
- }
-
- public static Single getInstance()
- {
- return s;
- }
- }
- class SingleDemo
- {
- static
- {
- System.out.println("c");
- }
-
- public static void main(String[] args)
- {
- Single ss = Single.getInstance();
- }
- }
复制代码
为什么结果不是c b a?
静态代码块不应该是随着类的创建而创建,优先于构造代码块执行吗?
|
|