Two Laptop Bag*
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

Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
The k & b Book says that an enum that isnt declared in a class can be marked only with public/default modifier, like a no-inner class.
But when I declare an enum as public. I get an error
class Nums is public, should be declared in a file named Nums.java.

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

This is obvious man. If you have a public class, then you must declare it in it's own file name. And since an enum is also a class internally, so you must create it in it's own file...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
Can you show the code, with the error message as well.
What name are you trying to save it with?


SCJP 6
How To Ask Questions On Java Ranch - How To Answer Questions On Java Ranch
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Hi ankit, I know its obvious. But when I read that line in k&b, I thought of trying it.
Sachin Adat
Ranch Hand

Joined: Sep 03, 2007
Posts: 213
Abhi vijay wrote:But when I read that line in k&b, I thought of trying it.

There's nothing wrong in trying, infact it is very right........but why are you getting the error....I guess it is solved
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
AS Ankit said, a source file can have only one public class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Enum
 
Similar Threads
private and protected enums
Strange Enum behaviour?
Declaring Enums in a class
Enum - Constant Specific Body
Enum doubt