Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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