String immutable class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

String immutable class

where is the initialized obj of String s="hello"; Class A{ public static void main(String[] args){ String s="hello"; s=s.concat(" world"); System.out.pruntln(s); } Above this prgmm ' s ' is a immutable class ,then i will assign value . The output is hello world . Its create a new obj . So where is the initialized obj . its gone or replace ? who can pointing to "hello"?

9th Sep 2017, 9:07 AM
JRaj Fx
JRaj Fx - avatar
1 Answer
0
It's in the stack, so after the scope it doesn't exist.
10th Sep 2017, 11:57 AM
StoneSmasher
StoneSmasher - avatar