Why does Java prohibit static fields in inner classes?

what I want to know is why java forbids static fields/methods inside inner classes Because those inner classes are “instance” inner classes. That is, they are like an instance attribute of the enclosing object. Since they’re “instance” classes, it doesn’t make any sense to allow static features, for static is meant to work without an … Read more

Are static fields open for garbage collection?

Static variables cannot be elected for garbage collection while the class is loaded. They can be collected when the respective class loader (that was responsible for loading this class) is itself collected for garbage. Check out the JLS Section 12.7 Unloading of Classes and Interfaces A class or interface may be unloaded if and only … Read more