This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes can you please explain the output of this program? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "can you please explain the output of this program?" Watch "can you please explain the output of this program?" New topic
Author

can you please explain the output of this program?

shoeb sayyed
Ranch Hand

Joined: Mar 14, 2010
Posts: 48


Thanks,
Shoeb
Baiju Scariah
Ranch Hand

Joined: Mar 17, 2005
Posts: 33
StringBuffer c=new StringBuffer("def");

and

"StringBuffer c" in "static void operate(StringBuffer b, StringBuffer c) " are not same.

When you call "c=b;", value of b is assigned to the temporary varibale, not to the c created in main().

So, if you print c in operate, result will be "abcdef", in main as it is not modified (only its copy is modified) it would print "def"..

Good to spend some time understanding differences between String & StringBuffer and concepts of pass by value & pass by reference..



shoeb sayyed
Ranch Hand

Joined: Mar 14, 2010
Posts: 48
thanks Baiju,

It was really helpful for me
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can you please explain the output of this program?
 
Similar Threads
String Objects