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
What programs use java?
How big is a 64 bit float?
What is the purpose of garbage collection in java? When is it used?
What are sets in java?
What is difference between java and java ee?
What does system.gc() and runtime.gc() methods do?
What is the difference between throw and throws keywords?
Where are local variables stored?
What is string made of?
Can a function return a function?
What is purpose of find feature?
How does thread synchronization occurs inside a monitor? What levels of synchronization can you apply?
What are actual parameters?
What is method in java with example?
How does enum work in java?