The answer is "I am not sure". After line "a=null", "Hello" is an abandoned, or orphan object. After the whole method is finished, all the Strings introduced in the method will be abandoned.
The fact that some objects are abandoned (no longer referenced) does not mean they will be garbage collected immediately. They may be claimed at once if your JVM lacks memory. They may float in JVM's memory until you shut down your JVM (done by System.exit(0) or by return in main() method), provided you machine has a big memory.
Hope this helps.
This post has been archived. It cannot be replied.