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
Why java is not 100% object oriented language?
What is a component in java?
Describe the ear, war, and jar.
Give some advantages of orm (object-relational mapping)?
What is a gui in java?
What does the web module contain?
What is event handling in java?
What do you mean by the deployment descriptor?
What are struts?
What is application component provider?
What is api in j2ee?
What is B2B?
What is distributed application?
Is java is fully object oriented?
What is javaserver pages standard tag library (jstl)?