Original Post
I'm trying to understand how Java handles references and such, and I don't quite get it. What I want to do is have two objects 'linked' so that I can just change one, and the other changes automatically. I was thinking of something like this: If I did something like that, and I changed the value of 'obj' would the values of nObj, and oObj change accordingly? Or how else would I accomplish something like this? PS:sorry for the terrible code, just coded it as an example, best I could think of righ tnow.
class NewObj
{
public Object obj;
public NewObj(Object tObj)
{
obj=tObj;
}
}
class OldObj
{
public Object obj;
public OldObj(Object tObj)
{
obj=tObj;
}
}
class Main
{
public static void main(String args[])
{
Object obj = new Object();
NewObj nObj = new NewObj(obj);
OldObj oObj = new OldObj(obj);
}
}