Monday, September 8, 2008

In java Object reference are passed by Value

class Dog{}

public void foo(Dog d)
{
d.serName("Fifi");
}

Dog myDog; //my Dog is a reference to a object of type Dog
myDog = new Dog();
foo(myDog); // The reference myDog to a object of type Dog is passed by Value

Result:
Dog name is changed to Fifi

http://javadude.com/articles/passbyvalue.htm

http://www.geocities.com/mcglonec1978/javacert/paramPassing_highres.html

No comments: