aspose 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


Win a copy of Spring in Action this week in the Spring forum!
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Argument Passing question