File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes enum Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "enum" Watch "enum" New topic
Author

enum

Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
why is this illegal?
enum Test{ a,b,3}; i think enum are used to hold any values so that we can limit the values



this is possible even though K&B says that enum cannot be in a method....then why in a static class? and why not in a static method?


scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
because a static inner class is actually a top level nested class.

and an enum is a list of constant values assigned to a type.


SCJP 1.6 96%
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
isnt 3 a constant? what if i create a enum Test{1,2,3}?
Neha Daga
Ranch Hand

Joined: Oct 30, 2009
Posts: 504
but 3 is different type then a&b.

i think enum{1,2,3} will do.
Raju Champaklal
Ranch Hand

Joined: Dec 10, 2009
Posts: 521
enum{1,2,3} doesnt compile...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

From the JLS

Nested enum types are implicitly static. It is permissable to explicitly declare a nested enum type to be static.

This implies that it is impossible to define a local enum, or to define an enum in an inner class


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Raju Champaklal wrote:enum{1,2,3} doesnt compile

How is enum {1,2,3} supposed to compile?? Is 1 or 2 or 3 a legal identifier??
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: enum