This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
When you create an enum, Java adds implicit modifiers to its members. For an example, I created a very simple enum:
and decompiled its .class file using a decompiler (JAD). Here's what I got:
As you can see in the above decompiled code, the enum constants are static members that are initialized within a static initializer. Try and decompile the .class file of your enum 'Animals' and see for yourself the implicit modifiers that are added to its members. This is the reason why your enum doesn't seem to behave the way you assumed :-)
Can we expect questions of this type in OCA7 exam.i have not encountered usage of non static init block with init block and enums while preparation for OCA7JP in K&B 6 book(Mala,However are such topics covered in your book for cert preparation)
A nice tricky example.
When The Going Gets Tougher,The Tougher gets Going