Let's say that I have a bunch of class instances that serve different purposes, so I want to be able to reference them directly by name:
SomeObject aardvark = new SomeObject();
SomeObject llama = new SomeObject();
SomeObject tiger = new SomeObject();
SomeObject chicken = new SomeObject();
But then I also want an array of them for easy iteration:
SomeObject[] animals = {aardvark, llama, tiger, chicken};
My question is this. What happens when I do this:
llama = new SomeObject();
I'll be creating a totally new llama object. How does this affect my animals array? Will it be referencing the NEW llama object, or somehow still referencing a copy of the old one?
I know Java is "pass by value", but I still get confused by stuff like this. When I use the NEW keyword, does the "value" of that object reference change? Thanks!