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

Can a serialized object be transferred via network?

519


What are the topics in core java?

536


What are the difference between string, string builder, and string buffer in java?

557


List implementations of list interface?

567


Write a function to print Fibonacci series and Tribonacci series?

762






What is final modifier?

560


What do you mean by Function Overloading in java?

637


what are synchronized methods and synchronized statements? : Java thread

583


How do you make a thread in java?

635


How to calculate the length of a singly linked list in java?

589


What is nullpointerexception in java?

528


How do you insert a line break?

501


Why lambda expression is used in java?

576


What are the important features of Java 8 release?

582


What is java util list?

489