Multiple choice technology programming languages

What is the output for the following lines of code? 1: String str = "Welcome"; 2: 3: str.concat(" to Java!"); 4: 5: System.out.println(str);

  1. A) Strings are immutable, compilation error at line 3.

  2. B) Strings are immutable, runtime exception at line 3.

  3. C) Prints "Welcome".

  4. D) Prints "Welcome to Java!".

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Java strings are immutable. Calling str.concat(" to Java!") creates and returns a new string object, but does not modify the original reference str. Therefore, printing str outputs the original value "Welcome".