This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Argument Passing question
 
Similar Threads
Object refrences
argument passing
what is the difference?????
Can someone talk about the reference?
Confused??? w/ Sample Code