Multiple choice general knowledge science & technology

What will be the value of str after line no.7?1 class string 2 {3 public static void main String ds[])4 {5 String str="A";6 str.concat("B");7 str+="C";8 }9 }

  1. A

  2. AB

  3. AC

  4. ABC

  5. compile-time error

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

Strings in Java are immutable - the concat() method returns a new String but does not modify the original. So str.concat("B") is ignored. The += operator creates a new String "AC" and assigns it back to str.