有人问过这个问题了:
http://expert.csdn.net/Expert/topic/1960/1960428.xml?temp=.1887628
再就是建议你用java的时候不要总想着C++

解决方案 »

  1.   

    你可以放到数组里。
    直接传递,是不可能的。
    void swap(int[] a)
    {
    int tmp=a[0];
    a[0]=a[1];
    a[1]=tmp;
    }
      

  2.   

    好像没有别的方法~
    你就把他们设为全局变量吧。或者用对象把它封装起来,当一个对象实例作为一个参数传给方法时,实际参数的值是该对象的引用。public class PassTest {
    float  ptValue;
    public void changeObjValue(PassTest ref) {
       ref .ptValue = 99.0f;
    }
    public static void main(String args[]) {
       String str;
       int val;
       PassTest pt = new PassTest();
       val = 11;
       pt.ptValue = 101.0f;
       pt.changeObjValue(pt);
       System.out.println("Current ptValue is:"+pt.ptValue);
    }
    }Current ptValue is:99.0
    pt是一个当前类的实例(即对象),pt实际上是指向该对象的引用。pt作为实在参数传递给changeObjValue()方法,虽然pt本身不改变,但对象的内容可以改变,所以在对象的成员变量ptValue改变后,打印的值为99.0。