• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in code

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
akaash singh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic