Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a string question from Marcus Green's todays question

 
Terry Kwan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Terry Kwan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but 3 says that "the value of a String object cannot be changed",is this wrong?
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcus has informed me that he has fixed ( or is fixing ) that question.
-Barry
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic