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 string args [] in java?

780


What is callable java?

751


What do you mean by platform independence? What is an interface?

803


In the below example, how many string objects are created?

790


What is length in java?

775


Why multiple inheritance is not supported by java?

752


What is a java object and java application?

810


Java.util.regex consists of which classes?

785


What do you mean by compiler?

823


How do you generate random numbers in java?

764


Is alive and join method in java?

779


Can I learn java without any programming experience?

797


Detail discussions on JVM, memory management and garbage collector.

756


What is java util concurrentmodificationexception?

718


What is java life cycle?

771