What will be the result of attempting to compile and run the following code?.
class MyClass {//from w w w . j a v a 2 s.c o m public static void main(String[] args) { String str1 = "str1"; String str2 = "str2"; String str3 = "str3"; str1.concat(str2); System.out.println(str3.concat(str1)); } }
Select the one correct answer.
println()
method.(d)
The program will print str3str1 when run.
The concat()
method will create and return a new String object, which is the concatenation of the current String object and the String object given as an argument.
The expression statement str1.
concat(str2) creates a new String object, but its reference value is not stored.