关于下面的程序,说法正确的是:
1. class StaticStuff 2 { 3. static int x = 10; 4. 5. static { x += 5; } 6. 7. public static void main(String args[]) 8. { 9. System.out.println(“x = ” + StaticStuff .x); 10. } 11. static 12. {x /= 3; } 13.}
1. class StaticStuff 2 { 3. static int x = 10; 4. 5. static { x += 5; } 6. 7. public static void main(String args[]) 8. { 9. System.out.println(“x = ” + StaticStuff .x); 10. } 11. static 12. {x /= 3; } 13.}
第5行和12行不能编译,因为该方法没有方法名和返回值。
第12 行不能编译,因为只能有一个static初始化块。
代码编译并执行,输出结果x = 10.
代码编译并执行,输出结果 x = 5.
代码编译并执行,输出结果 x = 15.