Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MindQ's question no. 11

 
susan george
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The statement...
String s = "Hello" + "Java";
yields the same value as..
String s="Hello";
String s2="Java";
s.concat(s2);
True or False?

The answer given is False.Why is it so?Can someone pls. help me?
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Susan,
Simple: no assignment is taking place. Just calling a string method without using the result will not alter the reference!
The stuff in bold is missing from your code to make the answer true:
s = s.concat(s2);
Regards,
Manfred.
 
susan george
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot,Manfred.I got it now.
susan
 
Haining Mu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Manfred Leonhardt:
Simple: no assignment is taking place. Just calling a string method without using the result will not alter the reference!
The stuff in bold is missing from your code to make the answer true:
s =s.concat(s2);

Question wording may cause problem, since s in s =s.concat(s2); is NOT the same object as s="Hello" + "Java"; although their string content are the same.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic