Explain the following statement: Java is always pass-by-value.

Answer Posted / qamrun nisa

Other languages use pass-by-reference or pass-by-pointer.
But 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) works.

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 ?    15 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How long does it take to master java?

451


What is container-managed transaction?

571


What is archiving?

546


Is object a composite data type in java?

486


What is isv?

507






What are the components and containers in java?

492


What is jaxr client?

519


What is asant?

563


How do you run a java program?

454


What is authorization?

579


What is java actionlistener?

468


What are j2ee technologies?

449


How do I become a java developer?

481


What is java listener?

491


What is application client?

519