File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Argument Passing question

Lydia Zhang

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�));

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.

SCJP Tipline, etc.
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

very nice animation Corey
Lydia Zhang

Joined: Feb 24, 2002
Posts: 29
Thanks Corey, you described very clearly.
I agree. Here's the link:
subject: Argument Passing question
jQuery in Action, 3rd edition