Pass By Value vs Pass By Reference
Pass By Value : In pass by value, the copy of the value of the argument passed from calling method and the parameter of the called method receives that value. Since it just a copy so any changes to the parameter inside called method doesn't reflect to the argument of the calling method.
Pass By Reference : In this case, the address of the argument is passed instead of value and the parameter of the called method receives that address like thought pointer in C.
But in Java there is no concept of Pointers. Since both the argument and parameter are references one can't hold the address of another rather holds the value of another reference. So every thing in Java is Pass By Value even though both are references.
Example of Proof :
OutPut:
Inside Memory :
No comments:
Post a Comment