When you have an object passed to a method and when the object is reassigned to a different one, then is the original reference lost

Showing Answers 1 - 17 of 17 Answers

Ashutosh Gupta

  • Jun 26th, 2005
 

No Reference is not lost. Java always passes the object by reference, now two references is pointing to the same object.

Bill Leonard

  • Oct 11th, 2005
 

In Java, it is ALWAYS pass by VALUE. Confusion occurs because all OBJECT variables in Java are references to objects. When we call a method in Java, the object reference is PASSED BY VALUE to the method (this means that a variable for the method's argument is created and the reference is COPIED to it).

pallavi

  • Aug 14th, 2007
 

Yes, we can create more copy of object.

  Was this answer useful?  Yes

Amit Patil

  • Sep 17th, 2007
 

@Bill:Pass by value of objects references is called pass by reference. In java its always pass by references unless we are dealing with primitives which is pass by value.

If a object is reassigned to a new refernces the original reference is not lost

  Was this answer useful?  Yes

Primitives are always passed by value.
Objects: Passed by value of reference. i.e. a copy of reference is passed into the method. Any changes to the reference itself will not be visible outside the method, so if you had another copy of the reference stored in a local/class variable it will retain the reference as it is.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions