0
In this line how many objects will created and how?
String st=new String("Ali");
3 ответов
+ 6
There would be 2 objects one in string pool and one on heap
+ 6
Creating New Strings:
Examples of how a String might be created, and let's further assume that no other String objects exist in the pool.
In this simple case, "abc" will go in the pool and s will refer to it:
String s = "abc"; // creates one String object and one
// reference variable
In the next case, because we used the new keyword, Java will create a new String object in normal (nonpool) memory and s will refer to it. In addition, the literal "abc" will be placed in the pool:
String s = new String("abc"); // creates two objects,
// and one reference variable
+ 1
Thank you guys.