集册 Java实例教程 Java中按参考值参数传递的示例

Java中按参考值参数传递的示例

欢马劈雪     最近更新时间:2020-01-02 10:19:05

539
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
Java中按参考值参数传递的示例

public class Main {
/*
来 自*
 时代Java - nowjava.com
*/

  public static void changeString(String s2) {

    System.out.println("#2: s2 = " + s2);

    s2 = s2 + " there";

    System.out.println("#3: s2 = " + s2);

  }


  public static void main(String[] args) {

    String s1 = "hi";

    System.out.println("#1: s1 = " + s1);

    Main.changeString(s1);

    System.out.println("#4: s1 = " + s1);  

  }

}