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
Explain the polymorphism principle?
What is a bufferedreader?
Can a class extends itself in java?
Can extern variables be initialized?
Explain the usage of this with constructors?
Why do we use regex?
Write a java program to count the number of words present in a string?
What is identifier in java?
What is the use of toarray () in java?
When a lot of changes are required in data, which one should be a preference to be used? String or stringbuffer?
What is called module?
What is the major difference between linkedlist and arraylist?
Explain when classnotfoundexception will be raised ?
What is formatted output in java?
Does constructor be static?