This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes doubt in call by... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "doubt in call by..." Watch "doubt in call by..." New topic
Author

doubt in call by...

sridevi kumar
Ranch Hand

Joined: Oct 17, 2001
Posts: 31
I have a doubt in calling the method...in java, it is call by value.
Is there any way to pass a character array in a method as a parameter and the called method should modify this parameter and the modified value must be reflected in the caller... Please help me.
For example:
void methodA( char[] reply )
{
/*this method shd modify the reply and the modified value must be reflected in the calling method*/
}

void methodB()
{
char[] data = new char[256];
methodA( data );
System.out.println( "data: " + data );
}
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
sure you can. your program works as you wrote it.
although java passes everything by value it actually passes in this case a refrence to the array (another copy refercne pointing to the same place).
to make things easier to understatnd (although not entirley correct) assume that when passing arrays or objects java passes them by refernce.
your program works and i have included an example to show it.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
You might want to take a look here to get a better idea of how parameters are passed in Java.
Corey


SCJP Tipline, etc.
sridevi kumar
Ranch Hand

Joined: Oct 17, 2001
Posts: 31
Thanks a lot for ur replies
 
Consider Paul's rocket mass heater.
 
subject: doubt in call by...