aspose file tools*
The moose likes Beginning Java and the fly likes output not clear Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "output not clear" Watch "output not clear" New topic
Author

output not clear

rakhee gupta
Ranch Hand

Joined: May 01, 2008
Posts: 43
Hi.I am running this program and it is printing value of y two times.why is it so? By my understanding it should print 42 only once.

class XCopy
{
public static void main(String [] args) {
int orig =42;
XCopy x = new XCopy();
int y=x.go(orig);
System.out.println(orig + " " +y);
}

int go(int arg) {
arg = arg *2;
return arg;
}
}
Vishal Matere
Ranch Hand

Joined: Jan 22, 2008
Posts: 81
You should see section Pass by value & Pass by reference in java books
And then you TELL me why its working so...


HTH
V


SCJP <br />SCWCD <br />SCBCD <br />SCEA-1
rakhee gupta
Ranch Hand

Joined: May 01, 2008
Posts: 43
i dont have any java book right now with me..i m studying thr internet..please please help me out
Vishal Matere
Ranch Hand

Joined: Jan 22, 2008
Posts: 81
Here you go rakhee,
See this
Hopefully you will understand O/P after reading it.

HTH
V
[ May 02, 2008: Message edited by: Vishal Matere ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Another recent posting about pass-by-value here. It quotes a couple of links, one the same as Vishal Matere posted (and it is a good link). Note the JavaRanch FAQ quoted in that other thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: output not clear