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

Are we allowed to change the transaction isolation property in middle of a transaction?

764


Can constructors be synchronized in java?

808


What is bean? Where can it be used?

787


Is the infobus client side only?

850


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

844


What are the different algorithms used for clustering?

767


What is the difference between a menuitem and a checkboxmenuitem?

753


What is the diffrence between a local-tx-datasource and a xa-datasource?

787


In inglish: How to convert jar to exe files? Em português: Como converter arquivos .jar para .exe?

2416


What is a class loader?

947


what are the activation groupworks?

1851


How a component can be placed on Windows?

2476


Is “abc” a primitive value?

805


Is the ternary operator written x : y ? Z or x ? Y : z ?

838


What is the relation between the infobus and rmi?

754