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 can we load a file of a user in the database table?
difference of inheritance and interface
If i learn Java, what kind of applications can i create that will help Banking, Retail, Hotel, Logistics industry.
Hi I have joined java course. I also want additional help from any tutorials website. Please suggest me tutorials which provides easy to understand online applet tutorials?
To identify IDL language what mapping mechanism is used?
What are the different approaches to represent an inheritance hierarchy?
How do you download stubs from a Remote place?
Is the infobus client side only?
difference between apllet and interface class
What event results from the clicking of a button?
What is the use of Class.forName
if i know the lenght of collection in hand, should I use Array or Arraylist? justify