Hi everyone
The code is from K&B chp 3 Quiz _ 4
class Mixer
{
Mixer() ---------------------------------> constructor with no-args
{
}
Mixer(Mixer m)--------------------------> constructor with ref var m
{
m1 = m; -------------------------> ref var m1 = m
}
Mixer m1; ----------------------------> class Mixer has an ref var m1 with no reference to an object (in other
word no object is created)
public static void main(
String args[])
{
Mixer m2 = new Mixer(); ----------------> fine
Mixer m3 = new Mixer(m2); ---------------------> ref var m2 is passed to Mixer class constructor Mixer(Mixer m) where we have m1 = m2
m3.go(); -----------------------------> Hi is printed
Mixer m4 = m3.m1; ------------------------> m4 ref var is equal to (ref var m3. ref var m1)-----------------> ?
m4.go(); --------------------------> Hi is printed
Mixer m5 = m2.m1; [b]--------------------------> m5 ref var is equal to (ref var m2. ref var m1)-----------------> ?
m5.go() -----------------> why Hi is not printed >
}
void go()
{
System.out.println("hi ");
}
}