0

In this line how many objects will created and how?

String st=new String("Ali");

20th Dec 2018, 8:59 AM
Ibney Ali
Ibney Ali - avatar
3 Antworten
+ 6
There would be 2 objects one in string pool and one on heap
20th Dec 2018, 9:53 AM
D_Stark
D_Stark - avatar
+ 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
20th Dec 2018, 10:11 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 1
Thank you guys.
20th Dec 2018, 3:54 PM
Ibney Ali
Ibney Ali - avatar