开发者

How many objects are created here - Java [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

How to know how many objects will be created with the 开发者_Python百科following code?

I have following lines of code in a program

String str1 = "abc";
String str2 = str1;
String str3 = "abc";

I want to know how many objects are created when above 3 lines of code is executed.


All the three references refer to the same interned String object.


2, 1 string object and the string contains 1 character array.


only one object is created. The rest(str2,str3) are referred to internal string pool.


It can create 0 or 1 object.

If there is already an interned String object with value "abc" no objects are created and if its not present, it gets created.


3 objects, but they all use the same interned string (i.e. the string only exists once in the running JVM).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜