Hi,
I was glancing over Sierra/Bates
Java 2 cert book and came across the following code example explaining pass-by-value semantics:
void bar()
{
Foo f = new Foo();
doStuff(f);
}
void doStuff(Foo g)
{
g = new Foo();
} From this code:
1. are g and f both referring to the SAME object? or are they 2 separate instances?
2. if g's object is somehow modified from whatever value f passed to it, will f's object also be modified?
I'm confused, because from the code, 2 different instances are created, but since f is passed into g, i'm not sure if that means that both variables are pointing to the SAME object?
Thanks in advance for your help.
JP