Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in call by...

 
sridevi kumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to take a look here to get a better idea of how parameters are passed in Java.
Corey
 
sridevi kumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for ur replies
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic