File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Argument Passing question

 
Lydia Zhang
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
very nice animation Corey
 
Lydia Zhang
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Corey, you described very clearly.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic