Why isn't a NullPointerException thrown if the instance of the Statics class is set to null? I understand that a static variable is shared amongst all instances and their is only 1 copy. Does this mean that static variables don't live on the heap? Well I guess that's what it implies?
So I guess the bigger question is where do static variables/methods live?
Consider the following:
public class Statics {
public static int count = 0;
public static void main(String[] args){
System.out.println(Statics.count);
}
}
public class StaticsTest {
public static void main(String[] args){
Statics t1 = new Statics();
t1 = null;
System.out.println(t1.count); //Output of zero was printed which I didn't expect.
}
}
If they don't live on the heap, I'm guessing they don't get garbage collected?