Regarding InnerClasses
I would be grateful if someone can explain why we cannot declare static variables inside an innerclass. I do understand that it throws syntax error saying that "static variables should be declared in static class or top layer". I want to understand what logical or philosphical reason is there behind this?
Thanks in advance!!
I think it's more to do with runtime efficiency than any deep philisophical reasoning. It means that inner classes don't need to have static initializers, or static space which would streamline the loading process.
I'm not sure, but it would make sense that an inner class actually shares the static variable area of the outer class, and can reference static variable more simply than references to statics from other classes.