Method Call by value and reference

  • Eclipse: Oxygen
  • Java: 1.8

Method Call by value and reference

Call by value means to call a method with a parameter as a value. Through this, the value of the argument is passed to the parameter.

Call by reference means call a method with a parameter as a reference. Through this, argument reference is used to pass the parameter.

In the following example, while passing a value to function outside the main function, the value in the main function remains unchanged as there is no actual change in the value in the desired memory location.

Output

Chaand

John

Steve

Pooja

Rahul

By while passing the value by reference, (such as we pass a pointer to the memory location in C) we can pass the array (which by default passes the address) so that the change can be seen in the variable.

Output

Salim

John

Steve

Pooja

Rahul

*************

Salim

Contributed by: Poonam Tomar


Full stack Java Developer

   Buy me a coffee!

 

PayTM QR (INDIA)

Download file

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu