Sunday, March 20, 2011

What is Call by Value & Call by Reference in Java-Swap Example-Java Interview Queston

Call By Value

Definition: It is a type of function call wherein the argument passed is of a primitive data type and the value of the argument gets copied to the parameter of the function and in the function definition even if we are swapping the values of the parameter we are actually swapping the copies of the argument not the actual argument.

Example


Call By Reference 

Definition: The argument passed in this type of function is an object type and not a primitive data type. Using call by reference the modifications can be done on the actual arguments because the references of the arguments are passed during the function call. 

Example

For details regarding Online Java J2ee Training please visit www.javatutoronline.com