class Mixer {
Mixer() {}
Mixer(Mixer m) { m1 = m; }
Mixer m1;
public static void main(String args[]) {
Mixer m2 = new Mixer();
Mixer m3 = new Mixer(m2); m3.go();
Mixer m4 = m3.m1; m4.go();
Mixer m5 = m2.m1; m5.go();
}
void go() { System.out.println("hi"); }
}
The answer to is " hi hi followed by an exception"
Here are my doubts:
a) When m2 is passed as an arg to Mixer constructor, are we passing the address to the Mixer() object m2 points to? If so, m1 = m will give the same address to m1 and hence m1 and m2 will point to same object?
b) How do you interpret m3.m1 and m2.m1? I mean to say, what is happening? I've seen RefVar.MethodInvocation as the syntax. First time coming across RefVar.RefVar. What exactly is happening? Object is created? Adresses are copied? I'm thoroughly confused :(
c) Finally how's the output coming the way it is?
Help please. Thanks, sincerely.