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

What is meant by method chaining?

671


To identify IDL language what mapping mechanism is used?

3424


Difference between DurableSubscription and non- DurableSubscription?

1724


What is a modular application?

604


Write a program to show synchronization?

700






What are local interfaces? Describe.

707


How would you detect a keypress in a jcombobox?

686


What is the difference between ear, jar and war file?

584


What are the different class loaders used by jvm?

610


Why are my checkboxes not being set from on to off?

652


How a component can be placed on Windows?

2278


What is the highest-level event class of the event-delegation model?

582


what are the activation groupworks?

1687


What restrictions are placed on the location of a package statement within a source code file?

627


What is the difference between the string and stringbuffer classes?

559