顺序是 静态属性、静态块、静态方法
我写了一个demo,- package lu.statics;
- public class StaticDemo {
- /**
- * @param args
- */
-
- static StaticDemo sd=new StaticDemo();
-
- static{
-
- System.out.println("static block");
-
- }
-
-
- private StaticDemo(){
-
- System.out.println("static element");
- }
-
- public static StaticDemo getSingle(){
-
- return sd;
- }
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
-
- staticMethod();
- }
-
-
- public static void staticMethod(){
-
- System.out.println("staticMethod");
-
- }
- }
复制代码 执行的结果是
static element
static block
staticMethod |