This is because in Java nothing as refernce is passed only the copy of the refernce is passed and while coming back from the called method the refernce copy is retained .
in main, you have a variable called c that refers to a car object.
when you pass that into your changeSpeed method, you have a SECOND variable that refers to the same object.
Then, in your changeSpeed method, you say
c = new Car();
now, the second variable points to a BRAND NEW CAR. the original c doesn't change what it's referring to, nor does it's car change.
so, you change the speed on the new car. then, when you leave that method, that reference falls out of scope, the new car becomes elligible for garbage collection.
then, you return to your main, where your original c is still referring to the original car, with it's original speed of 60.
it might make more sense if you change the method to have a different variable name... [ August 26, 2004: Message edited by: fred rosenberger ]
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
a bit of art, as a gift, the permaculture playing cards