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 do you mean by stack?

873


What is hash code collision?

807


What is style and indentation?

760


What is extension method in java?

791


Is class is a data type?

799


what is meant by Garbage collection?

827


What is array class in java?

793


Can we create a class inside a class in java?

744


Why does the integer quotient -0/3 yield 0, but the double quotient -0.0/3.0 yields – 0.0?

826


What are the 4 types of research methods?

691


Can you make a constructor final?

785


Difference between object instantiation and construction ?

817


What is the purpose of void class?

804


What are the types of strings?

779


What is object-oriented programming?

788