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
What is visibility mode?
Which class contains a method: cloneable or object?
How do I convert a string to an int in java?
Can a main method be declared final?
what is session in java?
What is a class reference?
Explain method overloading?
How do I convert a numeric ip address like 192.18.97.39 into a hostname like java.sun.com?
What are the differences between string and stringbuffer?
Why lambda expression is used in java?
Explain the difference between abstraction and encapsulation.
What are triggers in DB? Explain their types. How do they work?
Give me an example of array and linked list? Where they can be used?
What is the difference between inner class and nested class?
Write a program to reverse array in place?