PassbyReference PassbyValue in Java

Explain Pass by Reference and Pass by Value in Java?
Answer:
PASS BY REFERENCE:
Pass by reference means, passing the address itself rather than passing the value of the parameter.
Any changes you make to the variable being passed by reference will remain intact even after the function returns control.

PASS BY VALUE:
Pass by value means passing the value of the parameter.
A copy of the parameter you are passing is duplicated and passed to the function. If the function chooses to modify that value, it will be modifying the copy only and not the original value.
Once the function finishes, and control is returned to the returning function, the real variable passed will still remain the same.

0 comments:

Post a Comment