Mhhh. I'm still considering what you mean with "static variables" and "garbage collected".
Let's take a look at this class:
As soon as someone uses Foo.str, the class loader of the JVM will load the Foo-class. A String-object will be created (on the heap!) and str will be set to refer to this String-object. str itself is on the heap,too, but in the object representing the FOO-class.
As soon as someone would execute i.e.
the old
String object (the String-object with content "Hello World") is free for garbage collection.
The variable str will be existent as long as the class representation object will reside in the heap. It will "disappear" when the class Foo is unloaded (main
thread and all user threads terminated/JVM shuts down).