How many objects are created when we create String class
object using new operator?

Answer Posted / ravi

Eknath Wagadre is correct, Check this programme.

String s1 = "this is string";
String s2 = new String("this is string");

System.out.format("S1: %d, S2:%d \n",s1.hashCode(),s2.hashCode() );
System.out.println(s1.hashCode()==s2.hashCode() );

The both s1 and s2 have same hashCode, means only one object created.

Is This Answer Correct ?    0 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

When should the method invokelater() be used?

584


What is exception handling in java?

576


Explain the difference between runnable and callable interface in java?

589


How many classes can any class inherit java?

511


What are the data types supported by java? What is autoboxing and unboxing?

551






What is thread count in java?

548


What is replacefirst in java?

578


What is the purpose of static methods and static variables?

544


What is a method in coding?

571


Is it possible for a yielded thread to get chance for its execution again?

514


What is try-with-resources in java?

616


What are bind parameters?

555


What is definition and declaration?

530


describe method overloading

540


How do you create a reference in java?

512