GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 28 of 31    Print  
what is the difference between call by value, call by reference, call by address?
no answers


  
Total Answers and Comments: 5 Last Update: August 04, 2008     Asked by: bhatiagagan5 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: jamanat
 
I guess call by value and call by reference everyone knows.
In Java:
Call By value - premitive types passed in the method call, push their values on stack and hence said as called by Values.

Call By Reference - All objects passed to any method call, pass their reference on stack and hence said as called by reference.

Remiaining is call by address (should be same as call by reference), if not, the person may be addressing following:
     Static final member variables (constants) passed in the method call which are in the permanent memory and only the address (or reference) is pushed on stack. As the value on this address can not be changed (only read), the person is refering it as address and not reference.

Hope this helps. Even if you dont answer the person exactly, if you give above answer, interview pannel will understand that your concepts are clear and that's what you need to show.

Thanks,
Jamanat

Above answer was rated as good by the following members:
AmmiSudipto
December 26, 2007 06:17:19   #1  
jamanat Member Since: December 2007   Contribution: 3    

RE: what is the difference between call by value, call by reference, call by address?
I guess call by value and call by reference everyone knows.
In Java:
Call By value - premitive types passed in the method call, push their values on stack and hence said as called by Values.

Call By Reference - All objects passed to any method call, pass their reference on stack and hence said as called by reference.

Remiaining is call by address (should be same as call by reference), if not, the person may be addressing following:
     Static final member variables (constants) passed in the method call which are in the permanent memory and only the address (or reference) is pushed on stack. As the value on this address can not be changed (only read), the person is refering it as address and not reference.

Hope this helps. Even if you dont answer the person exactly, if you give above answer, interview pannel will understand that your concepts are clear and that's what you need to show.

Thanks,
Jamanat

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
February 13, 2008 04:06:46   #2  
sampra Member Since: February 2008   Contribution: 279    

RE: what is the difference between call by value, call by reference, call by address?
Java support call by value only

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
April 15, 2008 23:54:19   #3  
sachidanand Member Since: March 2006   Contribution: 1    

RE: what is the difference between call by value, call by reference, call by address?
Call by value: A copy of the argument is passed as parameter. So the caller method and the called method are working on different sets of data. Changing one doesn't affect the other

Call by reference:The address of the object on the heap, w.r.t java, is passed as the parameter. So modifying one will have an effect on the other.

Call by address: same as call by reference.

Hope your question is answered, if not already answered.

 
Is this answer useful? Yes | No
June 02, 2008 04:17:33   #4  
kayalsuku Member Since: June 2008   Contribution: 2    

RE: what is the difference between call by value, call by reference, call by address?
Java Does not support call by reference and it only support CALL BY VALUE
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
August 04, 2008 11:54:02   #5  
abhatnagar192006 Member Since: August 2008   Contribution: 1    

RE: what is the difference between call by value, call by reference, call by address?
JAVA does not support call by reference. As far as call by value is concerned..it means that java primitives are passed as arguments to a method.

Eg: void swapNumbers (int a, int b) ;

When we talk of passing by reference...we are actually passing "object references" by value.

Eg:

Class Student
{
.................
}

Class containsMain
{
public static void main (String args[])
 { 
   
   Student rajeev = new Student ("rajeev") ;
   Student mohan = new Student("mohan") ; 
   
   void swapObjects ( rajeev, mohan) ;
.............................
}
}

In the implementation of swapObjects, we have the folowing...

swapObjects (Student x, Student y)
{

Student temp = new Student (" ");

temp = x;
x = y;
y = temp;

}

Before, This function is invoked, x refers to rajeev and y refers to mohan.
During the function call, the reference of rajeev is copied to x and that of mohan is copied to y.

In the method, the object references are swapped.
However, when the method returns, x and y are abandoned, while the original references of the objects rajeev and mohan are still the same.

If JAVA supported call by reference, the swap would be successful..but it was not.

Summary: JAVA does not support call by reference, but only passing on references of objects by value

Aayush



 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape