String s = "Hi"; s.concat("!"); What is the value of s after these statements?
Correct answer
A. "Hi"
15 views
A. "Hi"
15 views
Java Strings are immutable, so concat() returns a new String and leaves s unchanged. The result is lost because it was never assigned. Writing s = s.concat("!") would give "Hi!".
Asked in: NTS, OCA Java, Technical Interviews
Not sure why the answer is A? Ask here and get an explanation.