File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enum

 
Abhi vijay
Ranch Hand
Posts: 509
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9496
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Sachin Adat
Ranch Hand
Posts: 213
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the code, with the error message as well.
What name are you trying to save it with?
 
Abhi vijay
Ranch Hand
Posts: 509
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ankit, I know its obvious. But when I read that line in k&b, I thought of trying it.
 
Sachin Adat
Ranch Hand
Posts: 213
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 509
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AS Ankit said, a source file can have only one public class.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic