This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line! See this thread for details.
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...
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.