If you reference an instantiated object in different classes, do changes get updated to the actual object or just the reference ..
public class First {
List<String> numbers;
public First(){
this.numbers.add("one");
this.numbers.add("two");
}
}
public class Second{
First InstanceOfFirst;
public Second(First F){
this.InstanceOfFirst = F;
}
public void printList(){
for(String s : this.InstanceOfFirst.numbers){
System.out.print(i+", ");
}
}
}
public class Third {
First Reference;
public Third(First F){
this.Reference = F;
}
public void Update(){
this.Reference.numbers.add("three");
}
}
So let's say my main looks likes this:
public static main(String args[]){
First F = new Frist();
Second sec = new Second(F);
Third th = new Third(F);
th.Update();
sec.printList();
}
Would I get one, two
or one, two, three
as a result.
I guess what I'm trying to ask is: Deos Java make different copies of objects when referenced like this or do they point to the same object??
Please excuse me if my question seems vague ..