Example of Pass by Reference Value Parameter Passing in Java - Java Object Oriented Design

Java examples for Object Oriented Design:Method Parameter

Description

Example of Pass by Reference Value Parameter Passing in Java

Demo Code

public class Main {
  public static void changeString(String s2) {
    System.out.println("#2: s2 = " + s2);
    s2 = s2 + " there";
    System.out.println("#3: s2 = " + s2);
  }/*from  w  ww. j  ava  2s .c  o m*/

  public static void main(String[] args) {
    String s1 = "hi";
    System.out.println("#1: s1 = " + s1);
    Main.changeString(s1);
    System.out.println("#4: s1 = " + s1);  
  }
}

Result


Related Tutorials