• 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

doubt in enums...anyone please help me out

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kathy sierra question doubt scjp 1.6

anyone please help me solving this code..... please explain in detail, dont forget to explain code no.4 and 6

thanks in advance



 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there anything specific you don't understand?? Also the code won't compile, this code will compile
 
Ranch Hand
Posts: 91
Notepad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

corrected your code so that it should compile
you left a blankspace(whitespace) in your class name
here the for loop is ineffective on the output of the program
since it ends up at next line see there are no openinig closing curly braces around the for loop
values() is a static method which gets the value of enum according to their index d2[2]
here we are providing index 2 which is WED in your enum
thus the output is WED
hope this solves your problem.
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

dilip kumarr wrote:
kathy sierra question doubt scjp 1.6

anyone please help me solving this code..... please explain in detail, dont forget to explain code no.4 and 6

thanks in advance







it a simple code.............
donot panic for this
what
for (Days d: Days.values() ); is doing is it is putting all the values of enum into a array days............if you remove this.......ur code will also compile fine............try it...

same for
Days [] d2 = Days.values();
so,when you see d2[2]..........it will pring d2 at index 2 which is WED

Any more confusion please telllll


 
reply
    Bookmark Topic Watch Topic
  • New Topic