Java call by value and call by reference

call by value:

If a method is to be called by passing a parameter as value then it is said to be Call by Value. Here the changes made to the passed parameter do not affect on called method.

Example of call by value:

Output:

call by reference:

If a method is to be called by passing a parameter(not the value) as a reference then it is said to be Call by Reference. Here the changes are made to the passed parameter effect on the called method.

Example of call by reference:

Output: