Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

String objects ..

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How many string objects are created prior to the output st..
and totally??




I thought the answer is 8 and 10.

But
"java.lang.String#concat(String). i.e. A String instance is created and returned, however, the return value is ignored and therefore, is not counted in the total count of String instances."

According to the above quote.
the answer will me 6 and 8..

Correct answer needed ???
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Soumy S:

But
"java.lang.String#concat(String). i.e. A String instance is created and returned, however, the return value is ignored and therefore, is not counted in the total count of String instances."

According to the above quote.
the answer will me 6 and 8..


I'm not sure, but i guess that the above statement does not actually refer to the number of Strings created. If "the return vale is ignored and therefore, not counted in the total number os instances", it doesn't mean that the Strings were not created. It just means that they were ignored and lost.

Originally posted by Soumy S:

I thought the answer is 8 and 10.


So do I. I may agree with the above statement and also stick with the opinion that 8 String objects were created prior to the last line and 10 Strings objects were created in total. However, i also agree that the above statement may cause some misunderstanding.
[ February 05, 2005: Message edited by: Leandro Melo ]
 
I child proofed my house but they still get in. Distract them with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic