Does Java pass arguments by value or reference?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can I have an action without a form?

593


What is the difference between long.class and long.type?

560


Describe, in general, how java's garbage collector works?

536


Is jvm a overhead?

623


Are enterprise beans allowed to use thread.sleep()?

647






Define the remote object implementation?

1999


Define aop(assepct oriented programing)?

631


Which container method is used to cause a container to be laid out and redisplayed?

664


Can I use javascript to submit a form?

612


What class is used to create Server side object ?

1668


How to pass parameters in RMI?

1687


To identify IDL language what mapping mechanism is used?

3412


Can I run seam outside of jboss as?

638


Why doesn’t the focus feature on the tag work in every circumstance?

563


What is synchronization and why is it important?

541