0 votes
in JAVA by
edited by

How many objects will be created in the following code?

search for more questions

2 Answers

0 votes
by

String s1="Welcome";  

String s2="Welcome";  

String s3="Welcome";  

Only one object will be created using the above code because strings in Java are immutable.

0 votes
by
String s = new String("Welcome");  

Two objects, one in string constant pool and other in non-pool(heap).

Related questions

+1 vote
asked May 31, 2020 in JAVA by SakshiSharma
0 votes
asked Apr 8, 2021 in JAVA by SakshiSharma
...