Explain pass by reference and pass by value?

Answer Posted / mohammad faisal

In java when we declares a variable, at runtime it
initialize and allocated a memory space.
Change in the value of variable result in the change of
output.
Now,
In pass by value,
when a value is passed, the function creates its own
variable and assign it the passed value.
So any change made by that function will not change the
value of actual variable which is passed.

In pass by refernce,
instead of passing the value we pass the address of the
variable. In this case, the function does not allocate any
memory to its variable but the variable just point to the
passed variable. Any change made by the function result in
change the value of actual variable.

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the disadvantage of synchronization?

547


What type of value does sizeof return?

526


Can set contain duplicates?

536


What is java jit compilers?

552


How can you generate random numbers in java?

575






What is difference between Heap and Stack Memory?

523


What are recursive functions?

567


Can subclass overriding method declare an exception if parent class method doesn't throw an exception?

497


Is java util list serializable?

525


What is meant by class loader? How many types are there? When will we use them?

495


Explain about interrupt() method of thread class ?

649


What is backdrop?

584


Why are getters and setters used?

560


What is a protected class in java?

525


Why vector class is used?

531