I understand that static variable or method is never garbage collected until the program ends, but how does a static nested class works? I found this quote in the oracle website and I know that a top-level class cannot be static so a nested static class will behave as a non-static class. But it does not ensure me if it will also be garbage collected in the same way.
A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.