File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Argument Passing question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Argument Passing question" Watch "Argument Passing question" New topic
Author

Argument Passing question

Lydia Zhang
Greenhorn

Joined: Feb 24, 2002
Posts: 29
Can anyone tells me why the result of the code fragment is "Blue"?
Button btn;
btn = new Button (�Pink�);
changer (btn);
System.out.println (btn.getLabel());
Public void changer (Button changeMe) {
changeMe.setLabel (�Blue�));
}
Thanks!


Lydia
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Because a reference to the button is passed to the method. Therefore, the method is able to modify the original object through the reference.
Look here for an animated demonstration of how parameters are passed in Java.
Corey


SCJP Tipline, etc.
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

very nice animation Corey
Lydia Zhang
Greenhorn

Joined: Feb 24, 2002
Posts: 29
Thanks Corey, you described very clearly.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Argument Passing question