aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B SCJP Study Guide for Java 5 ERRATA p 419 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B SCJP Study Guide for Java 5 ERRATA p 419" Watch "K&B SCJP Study Guide for Java 5 ERRATA p 419" New topic
Author

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

Harry Henriques
Ranch Hand

Joined: Jun 17, 2009
Posts: 206


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

Joined: Jun 17, 2009
Posts: 206
I see my mistake. There are eight String objects created prior to the System.out.println() statement.
 
wood burning stoves
 
subject: K&B SCJP Study Guide for Java 5 ERRATA p 419