Java String Immutability

Java String Immutability - - There were a total of eight...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
String s1 = “spring “; String s2 = s1 + “summer “; s1.concat(“fall “); s2.concat(s1); s1 + = “winter “; System.out.println(s1 + “ “ + s2); 1. What is the output? 2. How many String objects and how many reference variables were created prior to the println statement? - The result of this code fragment is “spring winter spring summer”. - There are two reference variables, s1 and s2.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: - 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....
View Full Document

Ask a homework question - tutors are online