Multiple choice technology programming languages

What will be the ouput of the following code snippet? String myString1 = "Hello World!"; myString1.replace('e', 'o'); System.out.println(myString1);

  1. Hallo World!

  2. Hello World!

  3. Compile time error

  4. NullPointerException

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

Strings in Java are immutable - the replace() method returns a new String object but does not modify the original. The line myString1.replace('e', 'o') creates "Hallo World!" but the result is discarded. Since myString1 is not reassigned, it still contains "Hello World!", which is printed.