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

How are the elements of a cardlayout organized?

596


What restrictions are placed on the values of each case of a switch statement?

535


Is infobus easy to use?

600


Name three component subclasses that support painting?

614


Can you give me a simple example of using the requiredif validator rule?

605






What is the difference between the session.update() method and the session.lock() method?

554


What is Remote Server?

1682


What is the immediate superclass of the applet class?

603


Why does the tag url-encode javascript and mailto links?

580


What classes of exceptions may be caught by a catch clause?

555


Define aop(assepct oriented programing)?

634


What is re-entrant. Is session beans reentrant. Is entity beans reentrant?

582


Can I map more than one table in a cmp?

590


Are there books about seam?

634


What is the purpose of the wait() method?

619