There is a question in the Enthuware's mock:
Annonymous inner classes cannot be static.
And it's true regarding to enthuware answer.
So what about it:
And my second doubt(that smth else ):
So there can be no blink static finals unless there is static initialization block. Blink static final can be initialized only at the time of referencing or inside the static initialization block. So static variables do not get their default values?
Lukas Smith wrote:So static variables do not get their default values?
Class fields whether static or non-static, don't get a default value if they are final.
Also the example that you gave of static anonymous class is wrong, first of all the code won't compile as you closed Test class after m method so the declaration of T is invalid. Also that anonymous inner class is not static. You can try this to confirm
I don't follow this - I have no problems compiling and running with a static anonymous inner class. Obviously though, I cannot invoke any new methods or members defined within that anonymous declaration; just what appears on the reference type.So why do Enthuware say an anonymous inner class cannot be static? I am worried I have a serious hole in my understanding.
Jason in your code, the anonymous inner class is not static. Only the reference variable anonJunk is static. Static inner classes can declare static fields in them. But if you try to add static fields to your anonymous inner class, then it will show an error, that proves that your anonymous inner class is not static...
Joined: Jun 09, 2009
Ah, right. I get what is being meant now.
The anonymous inner declaration that cannot be static, but the reference can be. After all, unless you have an instance of that anonymous inner class, you have no way to reference it and thus no way to access any static members that you might try to put in there.