aspose file tools*
The moose likes Mock Exam Errata and the fly likes MindQ's question no. 11 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "MindQ Watch "MindQ New topic
Author

MindQ's question no. 11

susan george
Greenhorn

Joined: Apr 17, 2001
Posts: 6
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

Joined: Jan 09, 2001
Posts: 1492
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

Joined: Apr 17, 2001
Posts: 6
Thanks a lot,Manfred.I got it now.
susan
Haining Mu
Ranch Hand

Joined: Jun 01, 2001
Posts: 51
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MindQ's question no. 11