___________________________________________________________________________
public class Test1{public static void main(
String[] args){String s="test";String s1 = new String("test"); System.out.println(intern());s=s1=null;}}
Ans-1
but , I get it why it is 1,but i want access that ungarbageble object and how to access it
__________________________________________________________________________
In my opinion ,in the above mentioned code you have created one object having two refrences.However you have also using intern,though calling intern() you need to specify the object either s or s1 ( in our case).
Let us suppose ,we called s.intern() . it means the "test" object would not be created and will only refreced to s1 from the private string pool of a class.( i belive you must have idea about string pool).
Assigning null to any refrence does not mean it will be garbage collected ,it just mean that " it eligible for garbage collection".
Hope it above justification would be helpful.
________________________
Mintoo
SCJP 1.4
__________________________