Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between pass by reference and call by reference?

Tags:

java

what is the difference between pass by reference and call by reference in java ?

like image 474
Jagan Avatar asked Sep 07 '10 15:09

Jagan


People also ask

What's the difference between pass by reference and pass by value?

Passing by reference means the called functions' parameter will be the same as the callers' passed argument (not the value, but the identity - the variable itself). Pass by value means the called functions' parameter will be a copy of the callers' passed argument.

What is the difference between pass by reference and pass by address?

Pass by reference (also called pass by address) means to pass the reference of an argument in the calling function to the corresponding formal parameter of the called function so that a copy of the address of the actual parameter is made in memory, i.e. the caller and the callee use the same variable for the parameter.

What is pass by reference and call by reference in C?

Passing by by reference refers to a method of passing the address of an argument in the calling function to a corresponding parameter in the called function. In C, the corresponding parameter in the called function must be declared as a pointer type.

What is the difference between call by reference and call by address?

Call By Address is a way of calling a function in which the address of the actual arguments is copied to the formal parameters. But, call by reference is a method of passing arguments to a function by copying the reference of an argument into the formal parameter.


2 Answers

Java does not pass any variables by reference.

It is tempting to think of objects being passed by reference in Java -- but harmful. Variables of object type are references. When passed, they are passed by value.

In other languages, pass-by-reference and call-by-reference are the same thing.

Edit: More detail is provided in the existing stackoverflow question "Is Java pass by reference?" (Spoiler: No.)

like image 126
Andy Thomas Avatar answered Nov 04 '22 15:11

Andy Thomas


Important concept - Java has no concept of "pass by reference". Everything in Java is passed by value. When you pass an object reference to a parameter in a method call, what you are really doing it is passing a value that points to the reference of your object.

The following URLs explain this in greater detail: http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html and http://javadude.com/articles/passbyvalue.htm?repost

Apparently (as noted in comments to your question) the terms "pass by reference" and "call by reference" mean the same thing.

like image 39
whaley Avatar answered Nov 04 '22 16:11

whaley