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

What is the preferred size of a component in java?

625


What is archiving?

701


What are the j2ee technologies?

652


Which server is best for java?

637


What is meant by applet in java?

673


What is webservices in java?

663


Is downloading java safe?

611


What is the J2EE module?

773


Is java procedural or object oriented?

645


Why java is interpreted language?

613


How does javac compiler work?

621


What is included in j2ee?

662


Is j2ee a programming language?

701


Is java 100 percent pure object oriented?

673


What is j2ee architecture?

635