How many of you say java method parameters are passed by value or passed by reference.There is a general view that primitive data type are passed by value but when it comes to object it is the other way around.I dont think that there is general agreement on this that object are passed by reference.

I am trying to convey my view that Java method parameters are passed by value and there is no other way.Even when the parameter is object it is the object variable which references to the same object that is being passed to it .So we get a feel that it is the object itself that is being passed but in reality it is not.

example
public void function(object a){
a.setmethod(x);
}


public static void main(){
object b= new object();
function(b);
}
What happeend here is the object varaible b was pointing to an object created by the constructor.It was passed to the method function.The value of b was passed to the object variable 'a' so 'a' and 'b' were refering to the same object and when "a.setmethod" was called we observed changes in the object it self.

Hosted by www.Geocities.ws

1