Given:
2. public class Main { 3. public static void main(String[] args) { 4. String s = "12"; 5. s.concat("ab"); 6. s = go(s); /*from w w w . j a v a2 s. com*/ 7. System.out.println(s); 8. } 9. static String go(String s) { 10. s.concat("56"); 11. return s; 12. } }
What is the result?
B is correct.
Strings are immutable.
If we captured the result of line 5, we would have "12ab", but we didn't capture that, so that String is lost.
Similarly, the result of line 10 is lost.