I guess call by value and call by reference everyone knows. In Java: Call By value - premitive types passed in the method call, push their values on stack and hence said as called by Values.
Call By Reference - All objects passed to any method call, pass their reference on stack and hence said as called by reference.
Remiaining is call by address (should be same as call by reference), if not, the person may be addressing following: Static final member variables (constants) passed in the method call which are in the permanent memory and only the address (or reference) is pushed on stack. As the value on this address can not be changed (only read), the person is refering it as address and not reference.
Hope this helps. Even if you dont answer the person exactly, if you give above answer, interview pannel will understand that your concepts are clear and that's what you need to show.
Thanks, Jamanat
Above answer was rated as good by the following members: AmmiSudipto
RE: what is the difference between call by value, call by reference, call by address?
I guess call by value and call by reference everyone knows. In Java: Call By value - premitive types passed in the method call, push their values on stack and hence said as called by Values.
Call By Reference - All objects passed to any method call, pass their reference on stack and hence said as called by reference.
Remiaining is call by address (should be same as call by reference), if not, the person may be addressing following: Static final member variables (constants) passed in the method call which are in the permanent memory and only the address (or reference) is pushed on stack. As the value on this address can not be changed (only read), the person is refering it as address and not reference.
Hope this helps. Even if you dont answer the person exactly, if you give above answer, interview pannel will understand that your concepts are clear and that's what you need to show.
RE: what is the difference between call by value, call by reference, call by address?
Call by value: A copy of the argument is passed as parameter. So the caller method and the called method are working on different sets of data. Changing one doesn't affect the other
Call by reference:The address of the object on the heap, w.r.t java, is passed as the parameter. So modifying one will have an effect on the other.
Call by address: same as call by reference.
Hope your question is answered, if not already answered.
In the implementation of swapObjects, we have the folowing...
swapObjects (Student x, Student y) {
Student temp = new Student (" ");
temp = x; x = y; y = temp;
}
Before, This function is invoked, x refers to rajeev and y refers to mohan. During the function call, the reference of rajeev is copied to x and that of mohan is copied to y.
In the method, the object references are swapped. However, when the method returns, x and y are abandoned, while the original references of the objects rajeev and mohan are still the same.
If JAVA supported call by reference, the swap would be successful..but it was not.
Summary: JAVA does not support call by reference, but only passing on references of objects by value