In Java, how are objects / values passed around

Showing Answers 1 - 36 of 36 Answers

Ashutosh Gupta

  • Jun 26th, 2005
 

In Java Object are passed by reference and Primitive data is always pass by value

  Was this answer useful?  Yes

Srinvasa Reddy

  • Aug 4th, 2005
 

In java the Objects are passed by reference But internally it is pass by value. 
primitive data is directly pass by value

  Was this answer useful?  Yes

nowfaldaan

  • Mar 29th, 2007
 


Hi Ashutosh Gupta, I think you are absolutely wrong, in java there is no pass by reference, only pass by value even if it is object

paluri

  • Apr 1st, 2007
 

yes, only there is call by value is there in java ,but we can pass an object to a method so....in this case we can call as call by reference na.,...

  Was this answer useful?  Yes

MOHD IFTAKHAR

  • Apr 10th, 2007
 

Sorry dear, There is no callby-reference concept?in JAVA.

  Was this answer useful?  Yes

KAPIL

  • Jul 8th, 2007
 

Objects are passed as references which imples thaqt when paramter toa method is an object then the changes made to that object will be reflected in the class calling that method, however if the method is having a primitive paramter like int x then the values changes made to x will not be reflected in the class calling that method
eg
class c { method ( obj1, x) ; } //here obj1 is passed by reference object and x is like int x variable which is a primitive
now in methd( class obj, int x)
{
x=0; obj =new class("new1", new2");//here the new values of obj will be reflected in //class c and there will be no change for x in class c

}
if all what i said above makes sense then you know a little of java but if it doesnot then dont go for the interview :) as you would need to understand bacis of java :)

  Was this answer useful?  Yes

Prateek Kumar

  • Jul 14th, 2007
 

Even if there is no call by reference in java.....passing around of objects automatically happens using reference (that's the reason why there is no explicit call by reference)
, just like there is no multiple inheritence but interfaces to fulfill the needs of programming. Correct me if i am wrong

  Was this answer useful?  Yes

Amit Patil

  • Sep 17th, 2007
 

Objects in Java are passed as pass by reference. There is nothing such as using pass by value internally. Objects are never actually passed in any programming language. In C we use pointers where we pass the reference of object. There also this method is called pass by reference. In Java similar concept is used. Internally references are passed instead of pointer. However it is only called PASS BY REFERENCE and nothing else :-)



Pass By value is where the value of primitive are copied. Any modification of values in any function are not reflected in main program in pass by value.

  Was this answer useful?  Yes

aar bee

  • Nov 14th, 2007
 

It is always pass by value.  For non-primitives a copy of the reference is passed.

nnandurkar

  • Jun 23rd, 2010
 

Java supports only pass by value. If it is a primitive then copy of the value is passed. And if it is an object then copy of its reference is passed.

  Was this answer useful?  Yes

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