How, then, can I pass an object to a method, and have the method change the reference so it points to a different object back in the calling code?
• A. There are two ways. The obvious way is “just add another level of indirection” — wrap the object in another class, whose purpose is simply to be passed as a parameter, allowing the nested object reference to be modified. The second alternative is a clearer variant of this. Pass in a single element array. Since arrays are objects, this works. • void jfoo(Object ref[]){ ref[0] = new Object(); } … Object kludge[] = new Object[1]; kludge[0]= myObj; jfoo(kludge); if (kludge[0] == myObj) … else … Note that changing a global variable/object inside a method is an egregious programming practice — it usually violates basic OOP constructs.