Possible Duplicate:
Is Java pass by reference?
How come this code of mine is not working? I am passing an object into a method but it won't modify the original object that I created in main, why is that?
public class TestRun{
public static void main(String[] args){
Test t1 = new Test();
Test t2 = new Test();
t2.x = 555;
t2.y = 333;
System.out.println("The original valuess of X and Y are");
System.out.println("X = "+t1.x+"Y = "+t1.y);
modifyObject(t1,t2);
System.out.println("After the modification ");
System.out.println("X = "+t1.x+"Y = "+t1.y);
}
public static void modifyObject(Test arg1,Test arg2){
arg1 = arg2;
}
}
public class Test{
int x = 9999;
int y = 1;
}