| 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?
|
|
|