Win a copy of Terraform in Action this week in the Cloud 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

K&B SCJP Study Guide for Java 5 ERRATA p 419

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


What is the output? For extra credit, how many String objects and how many
reference variables were created prior to the println statement?

Answer: The result of this code fragment is "spring winter spring summer". There
are two reference variables, s1 and s2. There were a total of eight String objects
created as follows: "spring", "summer " (lost), "spring summer", "fall" (lost), "spring
fall" (lost), "spring summer spring" (lost), "winter" (lost), "spring winter" (at this point
"spring" is lost). Only two of the eight String objects are not lost in this process.



I think the Answer: is incorrect, There are a total of nine String objects created as
follows: "spring " (lost), "summer " (lost), "spring summer ", "fall " (lost), "spring fall " (lost),
"spring summer spring " (lost), "winter " (lost), "spring winter ", and " " (lost).
Only two of the nine String objects are not lost in this process.

What do you think?
 
Harry Henriques
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see my mistake. There are eight String objects created prior to the System.out.println() statement.
 
reply
    Bookmark Topic Watch Topic
  • New Topic