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
What does web module contain?
What type of code is java?
What is the container?
What are the topics in j2ee?
What is interpreter in java?
What is java api for xml-based rpc (jax-rpc)?
What should a junior java developer know?
What is Document Object Model?
What is DDP?
What are the technologies a java developer must know?
What is event in java?
Is java a web technology?
How many types of constructors are there in java?
What is jlayeredpane java?
What is web container in j2ee?