jump to navigation

Argument passing July 28, 2005

Posted by Coolguy in J2SE.
trackback

Call by value:
This method copies the value of an argument into the formal parameter of the sub-routine. Therefore, changes made to the parameter of the sub-routine have no effect on the argument used to call it. In Java when a simple type is passed, it is passed by value.

Call by reference:
In this method, a reference to an argument (not the value of the argument) is passed to the parameter. Inside the sub-routine, this reference is used to access the actual argument specified in the call. So, the changes made to the parameter will affect the argument used to call the sub-routine. When you pass an object to a method, it is passed by reference.
When an object reference is passed to a method, the reference itself is passed by value. However, since the value being passed refers to an object, the copy of that value will still refer to the same object that its corresponding argument does.

Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: