通过 new 创建的对象可以实现回传,如数组;自定义类对象里的参数。 

【数组方式】

public static void main(String[] args)
{
try
{
int [] amount= new int[1];

amount[0] =1;

Test2(amount);
// 将显示 amount的赋值后的结果99  
System.out.print(amount[0]);
}
catch (Exception e)
{
e.printStackTrace();
}
}

private static void Test2(int[] amount) throws Exception
{
amount[0] = 99;
}

 

【自定义类对象方式】

// 函数传入自定义类,测试回传
// -------------------------------------------
MyParam param= new MyParam ();
param.a = 0;
param.b = 0;
// 引用有效
setValue(param);   //在函数里面对param的a和b赋值操作
// 得到赋值后的结果
System.out.println(value.a);
System.out.println(value.b);

 

相关文章:

  • 2021-12-06
  • 2021-08-03
  • 2021-12-05
  • 2022-12-23
  • 2021-11-08
  • 2021-07-05
  • 2021-06-10
  • 2021-09-29
猜你喜欢
  • 2021-11-03
  • 2021-07-15
  • 2021-11-13
  • 2021-09-11
  • 2022-02-03
相关资源
相似解决方案