What will be the result of attempting to compile and run the following program?.
public class Main { public static void main(String[] args) { String str = new String("test"); str.concat(" mtest"); StringBuilder strBuilder = new StringBuilder(" main"); strBuilder.append(" mo"); System.out.println(str + strBuilder); } }
Select the one correct answer.
mtest
main mo, when run.mtest
main mo, when run.mtest
main, when run.(d)
The program will construct an immutable String object containing "test" and a StringBuilder object containing " main".
The concat()
method returns a reference value to a new immutable String object containing test mtest
, but the reference value is not stored.
The append()
method appends the string " mo" to the string buffer.