Answer: Objects passed to the method are never garbage collected in that method. So p cannot be GCed. x is not an object. "abc" is a string literal which goes to the string pool and is not GCed. So, only a is eligible for GC.
1> even after the method returns the string literal isn't GCed? 2> what if i explicitly assign null to str: str=null; ?
The reason why strings are not GCed is because, String will be handled in a different way than all the other Objects. Even though String IS-A Object, the memory handling of Strings are different. This is called String Pool. Before even creating a new String Literal say for example "Sutaria" in the pool, it will check for the existance of the string. If it can't find one then it will create. So lets come your question
1) Even after the method returns, the string literal won't be GCed.
This is because the String pooling
2) If you create String s=null; This will not create a String Object at all (unless you mention String s = "null" .This is because you have just given a reference 's' and not actually created an Object.