The output of the last one is 99 because "void changeIt (Bar myBar)" declares a local Bar variable named myBar. This local variable is passed the reference to your Foo.Bar object. What this means is that "myBar.barNum=99;" says take the Bar object that myBar is referencing (which is Foo.Bar object) and set the barNum to 99. Then "myBar = new Bar();" says take our local Bar object and have it reference a brand new Bar object instead of the Foo.Bar object. Next you change the barNum value of your new Bar object which has no effect on Foo.Bar at all.
I think the main confusion comes from the fact that the local variable myBar is givin a reference to another variable with the same name. This is allowed but can get confusing when changing references AND values.
Also, if you didn't write this code please state your sources.