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
Can It is possible to synchronize the constructor of a Java Class?
What is JDBC Driver interface?How can you retrieve data from the ResultSet
How to create a thread in java?
How does singleton class work?
What is the purpose of file class?
What does || mean in vectors?
What is java volatile?
What is thread synchronization in java?
What is entry set in java?
How do you convert bytes to character in java?
In the below example, how many string objects are created?
What is a newline character in java?
Can you change array size in java?
Can final class have constructor?
Can you inherit a constructor java?