Skip to content

Instantly share code, notes, and snippets.

@MericBERBER
Created June 13, 2017 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MericBERBER/4ae02fa48992e696bbbcba52f5db5296 to your computer and use it in GitHub Desktop.
Save MericBERBER/4ae02fa48992e696bbbcba52f5db5296 to your computer and use it in GitHub Desktop.
class PassByReferenceTest {
public static void main(String args[]){
PassByReference object = new PassByReference();
System.out.println("In main method adress [1] --> " +object);
System.out.println("In main method value [1] --> " +object.getValue());
change(object);
System.out.println("In main method adress [2] --> " +object);
System.out.println("In main method value [2] --> " +object.getValue());
}
private static void change(PassByReference o){
System.out.println("In change method adress [1] --> " +o);
System.out.println("In change method value [1] --> " + o.getValue());
o.setValue("New Value");
System.out.println("In change method value [2] --> " + o.getValue());
PassByReference object2 = new PassByReference();
o = object2;
System.out.println("In change method adress [2] --> " +o);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment