This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enum

 
Abhi vijay
Ranch Hand
Posts: 509
  • 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: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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
  • 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
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AS Ankit said, a source file can have only one public class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic