Does Java pass arguments by value or reference?
Answers were Sorted based on User's Feedback
Answer / prs01
Pass by value.
1. When passing primitives, it passes a copy of the
variable to the method. Any change made in the method does
not reflect in the calling method.
2. When dealing with objects, a copy of their
reference/address is passed. Thus the change made to the
object is reflected in the calling method.
| Is This Answer Correct ? | 22 Yes | 4 No |
Answer / mr.h
In Java no matter what type of argument you
pass the corresponding parameter (primitive variable or object reference) will get a copy of that data, which is
exactly how pass-by-value (i.e. copy-by-value) work.
In Java, if a calling method passes a reference of an object as an argument to the called method then the passedin
reference gets copied first and then passed to the called method. Both the original reference that was
passed-in and the copied reference will be pointing to the same object. So no matter which reference you use, you
will be always modifying the same original object, which is how the pass-by-reference works as well
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vamsi krishna.i
Java Always takes arguments by reference Only.
| Is This Answer Correct ? | 0 Yes | 7 No |
How would you reatach detached objects to a session when the same object has already been loaded into the session?
What is thread deadlock? How to resolve thread deadlock?
what is a dirty read?
What is the priority of Garbage collector thread?
For an example, if we have some variable in run method, and we created one or more threads. Does all threads will share the same variable or a copy of variable is created for each thread??
cud u help me ... i am struggling with this question... to find all the subsets of a given set for ex.... a,,b,c shud give all the subsets.... i gt the program in c bt nt able to get it in java..... help needed ..
what are memory considerations of jsp compares to other web components?
how to create Calculator GUI using Gridbaglayout as like as Window Calculator??????????? (Open calculator Go-->Run-->type calc-->Enter)
Name the method to find, if a thread is active or not?
What is the map interface?
How do you set security in applets?
how team leaders assign work for the team member like through papers,word document