This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Thanks for your reply! Well, is that a rule? I was actually writing the code as I usually write for any other class..first instance varibales, then constructors etc.. enum is also a class, right? Then, why such different behavior? Know any explicit reasons? Thanks again!
Chandra Bhatt
Ranch Hand
Joined: Feb 28, 2007
Posts: 1707
posted
0
It is mere a rule and I don't find any reasoning behind that yet:
Java requires that the constants be defined first, prior to any fields or methods. Also, when there are fields and methods, the list of enum constants must end with a semicolon.
Note: The constructor for an enum type must be package-private or private access. It automatically creates the constants that are defined at the beginning of the enum body. You cannot invoke an enum constructor yourself.