File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Enums and access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Enums and access " Watch "Enums and access " New topic

Enums and access

dave hopkins

Joined: Oct 27, 2006
Posts: 25
I have read that when enum's are declared within a class, a separate class must use the surrounding class to access the enum. But the following compiles & runs fine.

What gives?
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
I get a compilation error when I try it. I suggest you check to see if you've got an old TimeZone.class file lying around somewhere in your class path, and delete it.

"I'm not back." - Bill Harding, Twister
Kail Limas

Joined: Jul 09, 2007
Posts: 24
Actually the class is unnecesary. You can use the class. But then you need to add "Numnum." to the output.

Without the class you can just leave it be as is.

At least it works in Eclipse that way.
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Your code runs and compiles fine, but the reason is that the enum class has now default access. So you can only use it within your package.

If you want to use your enum outside your package. You must mark your enum public and this will give a compile error because in Java you can have only one public class in a file. In that case you have to define your enum outside the class.

Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
I agree. Here's the link:
subject: Enums and access
It's not a secret anymore!