1.

How Many Objects Will Be Created On Executing The Following Code For Creation Of A String Using The String Literal?

Answer»

String str1=”DeZyre”;

String str2=”DeZyre”;

String str3=”DeZyre”;

Only one object will be CREATED because EVERY time when we create a string literal, the JVM checks for the PRESENCE of the string in the string constant pool. Only if the string is not present in the pool then a new string instance will be created, otherwise a REFERENCE to the pooled instance is returned.

String str1=”DeZyre”;

String str2=”DeZyre”;

String str3=”DeZyre”;

Only one object will be created because every time when we create a string literal, the JVM checks for the presence of the string in the string constant pool. Only if the string is not present in the pool then a new string instance will be created, otherwise a reference to the pooled instance is returned.



Discussion

No Comment Found