aspose file tools*
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
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
 
 
subject: can you please explain the output of this program?
 
Similar Threads
String Objects