Vaibhav Gargs wrote:IF we have some static variables in the class, then, at what time they are garbage collected?
The static variable will live as long as the class is loaded in the JVM. When there are no more instances of the class being ran in the JVM the class will be unloaded and the static variable will be eligable for garbage collection.
"The only way that a Class can be unloaded is if the Classloader used is garbage collected. This means, references to every single class and to the classloader itself need to go the way of the dodo."
If you think about it, classes cannot be garbage collected just because there are no instances of the class. Some classes only have static variables and methods so no instance can ever be created. Classes are loaded when they are referenced for the first time and only unloaded if the classloader is garbage collected.
To answer the original question: for all practical purposes the answer is that they are never garbage collected.