What will be the result of attempting to compile and run the following code?
public class Main{ public static void main (String args [] ){ String str1 = "str1"; String str2 = "str2"; System .out.println ( str1.concat (str2) ); System .out.println (str1); } }
Select 1 option
Correct Option is : D
String objects are immutable.
The original object will remain the same and a new object will be returned no matter what operation you do.
The statement str 1.concat(str2) creates a new String object which is printed but its reference is lost after the printing.