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 visibility mode?

525


Which class contains a method: cloneable or object?

538


How do I convert a string to an int in java?

547


Can a main method be declared final?

580


what is session in java?

742






What is a class reference?

550


Explain method overloading?

568


How do I convert a numeric ip address like 192.18.97.39 into a hostname like java.sun.com?

598


What are the differences between string and stringbuffer?

585


Why lambda expression is used in java?

568


Explain the difference between abstraction and encapsulation.

535


What are triggers in DB? Explain their types. How do they work?

621


Give me an example of array and linked list? Where they can be used?

552


What is the difference between inner class and nested class?

548


Write a program to reverse array in place?

584