aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Problem in code 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 "Problem in code" Watch "Problem in code" New topic
Author

Problem in code

akaash singh
Ranch Hand

Joined: Jul 04, 2009
Posts: 45
hey everyone ,

i have a doubt in the following code :



the doubt i have is : Since static methods cannot directly access non-static members , how are we able to directly access the enum Days in the main method , without an object of the class TestDays . Are enums inside a class not considered as instance variable ?


[HENRY: added code tags]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18846
    
  40

Are enums inside a class not considered as instance variable ?


In Java, "enum" is not the type, it is a keyword to declare the type. So... days is not a variable, static or instance.

In fact, using "Days" is more similar to using a nested class than a variable (or at least, it is probably easier to think of it that way).

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ken Truitt
Ranch Hand

Joined: Aug 23, 2007
Posts: 124
All the references refer to enums as a type of constant and that they are implicitly public, static and final--so when an enum is
defined within a class, you don't need to access it via a reference to the class. And you can refer to an enum defined
outside a class definition similar to how you would refer to a static entity of another class.


SCJP 88% | SCWCD 84%
akaash singh
Ranch Hand

Joined: Jul 04, 2009
Posts: 45
Thanks Henry and Ken ,

Can you also suggest some material from where i can read more about enums , as of now i have the kathy and berts book.

Regards aakash
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in code