Does Java pass arguments by value or reference?

Answers were Sorted based on User's Feedback



Does Java pass arguments by value or reference?..

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

Does Java pass arguments by value or reference?..

Answer / sujini

java pass arguments only pass by value

Is This Answer Correct ?    4 Yes 1 No

Does Java pass arguments by value or reference?..

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

Does Java pass arguments by value or reference?..

Answer / roshni

yes by both

Is This Answer Correct ?    4 Yes 11 No

Does Java pass arguments by value or reference?..

Answer / vamsi krishna.i

Java Always takes arguments by reference Only.

Is This Answer Correct ?    0 Yes 7 No

Post New Answer

More Advanced Java Interview Questions

In howmany ways a thread can be created?

3 Answers   HCL,


How are the elements of a borderlayout organized?

0 Answers  


What is Connection Pooling?

1 Answers   Enteg Technologies, Infosys, Polaris,


Difference between hashmap and hashtable?

0 Answers  


what is disadvantage of thread?

3 Answers   HCL,






What is rmic?

4 Answers  


what is the Scope of Final Keyword in Java?

1 Answers   HCL,


Can I map more than one table in a cmp?

0 Answers  


what is the proxy pattern?

1 Answers  


What is Stream and Types?

2 Answers   Patni,


What is clustering? What are the different algorithms used for clustering?

0 Answers  


1) what is synchronization? 2)write a program to show synchronization ? 3) what is orm? 4) what is getTemplete method and hw u use it? 5)write a singleton program ? 6) what is IOC concept & explain it? 7) methods of spring? 8)explain spring framework? 9)what are the oops concept? 10)what r the diff types of exception? 11)what is AOP(assepct oriented programing)? 12)jsp life cycle? 13)servlet life cycle? 14)how to u catch ur exception when executing a query in hibernate? 15)write javascript function? 16)write a querry to join two tables? 17)wap to show inheritance and use of interface? 18)explain the project? 19)in spring bean class uses singleton or prototype? 20)Explain prototype?

1 Answers   Cap Gemini,


Categories