wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes a string question from Marcus Green's todays question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "a string question from Marcus Green Watch "a string question from Marcus Green New topic
Author

a string question from Marcus Green's todays question

Terry Kwan
Greenhorn

Joined: Nov 16, 2002
Posts: 8
Which of the following statements are true?

1 A String created with the new keyword will cause a new String object to be created.
2 A String reference created without the new keyword will not necessarily cause a new String object to be created
3 Once created, the value of a String object cannot be changed
4 The value of a String object can be changed using the setValue method.
I think the 1,2,3 are true,but the answer is 1,2.
what's the correct answer?
[ December 03, 2002: Message edited by: Terry Kwan ]
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
3 is wrong, String object are immutable, once created, there is no way to change any character of the string. All mutating methods you invoke on a String object will return you a new String object.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Terry Kwan
Greenhorn

Joined: Nov 16, 2002
Posts: 8
but 3 says that "the value of a String object cannot be changed",is this wrong?
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
yes! options 3 and 4 are wrong.
You can change the value of a String object. The qn does'nt mean changing the individual characters in the value of the string.
Ikechukwu Morah
Greenhorn

Joined: Nov 01, 2002
Posts: 18
Originally posted by Valentin Crettaz:
3 is wrong, String object are immutable, once created, there is no way to change any character of the string. All mutating methods you invoke on a String object will return you a new String object.

If a String object is immutable, then from the question, the option 3 is also correct.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Notice that there is a feedback button when you
get the answer to Marcus's Question Of The Day.
If you have doubts use it.
-Barry


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Marcus has informed me that he has fixed ( or is fixing ) that question.
-Barry
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Sorry, from the explanation I gave 3 is clearly true. I just kind of mistyped what I had in mind
Marcus Green
arch rival
Rancher

Joined: Sep 14, 1999
Posts: 2813
It was wrong and now it is fixed, once created a String cannot be changed. Hmm perhaps I should have the ability to easily post a comment about the question...
This was from question of the day system at www.examulator.com
Marcus


SCWCD: Online Course, 50,000+ words and 200+ questions
http://www.examulator.com/moodle/course/view.php?id=5&topic=all
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a string question from Marcus Green's todays question
 
Similar Threads
Let's have a look!
how many String object have been created?
Constructors
Question from Jamie's Book
String objects