String s= "test"; String s1= new String("test"); String s2= new String("test"); String s3= new String("test");
each time a new String object will be created and assigned to the reference variables s, s1, s2, s3 respectively. so there are totally 4 String objects created in heap.
but since you declare it with string literals, the first time a string literal is found its added to string constant pool memory.
Next time onwards if you declare another String literal with same String content value its not created afresh and previously created string literal will be reused and its address will be assigned to second reference and so on..
String s= "test"; //"test" is placed in String constant pool
String s1= "test";// here no String object is created instead s1 contains the address of above String object created at line 
//likewise all s2 and s3 will contain address of Object created at  String s2= "test"; String s3= "test";
so ultimately only 1 object is created.
I hope I answered correctly. [ April 08, 2008: Message edited by: vijaya saradhi ]
Yes i would say both of them are correct tentatively based on the context!
If at all the question has been asked that "how many objects are created in this method?" and all the aforementioned strings are part of a method, then th e answer is none.
Why because, the string "test" is being a literal,it is created when the class is being loaded. If it is having a "new", of course definitely there is a brand new string object created for you in heap!
Had they been an instance variables, there is only one string object created during the class loading operation!
Hope this helps! :cheers: [ April 08, 2008: Message edited by: Raghavan Muthu ]
Moreover you don't need to bother much about it if at all this question was based on the Garbage Collection, as Bert bates had been telling that the exam has taken out the Garbage Collection questions which involves Strings as the strings are never ever GC'ed because of String Literal Pool.