static {
只执行一次的代码.
}

解决方案 »

  1.   

    static用来修饰变量的话它可以用类名来访问,用来修饰方法的话不用实例化类就可以调用,它的作用就是这样啊。
      

  2.   

    稍作修改即可
    package com.sunqh.fastener;class testa{
    private static String vvx = null;               ------------修改
    public static testa ta;

    public static testa getInstance(){
    // if(ta == null)                         ----------删除
                      { 
    ta= new testa();
                        if(vvx  != null){                   -----------增加
    ta.teststatic2();
                        }  
    }
    return ta;
    }
    public void teststatic2(){
    vvx = "ddd"+"ooo";
    System.out.println("---operating...---");
    }

    public String getVVX(){
    System.out.println("---return---"+vvx);
    return vvx;
    }
    }public class test{
    public static void main(String[] args){
    testa.getInstance().getVVX();
    testa.getInstance().getVVX();
    }
    }
      

  3.   

    补充:
         vvx = "ddd"+"ooo";
    ----->
          testa.vvx = "ddd"+"ooo";