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
How does compareto work in java?
Is java call by reference?
What is string in java is it a data type?
What are data structures in java?
Can private members of a base class are inheritable justify?
Explain importance of throws keyword in java?
How do you sort a string in java?
Why wait and notify methods are declared in object class?
Is 0 an irrational number?
Can we use string in switch case in java?
What are the uses of java?
Why hashmap is used in java?
Which java version is latest?
When will you define a method as static?
Differentiate between static and non-static methods in java.