This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in enums...anyone please help me out

 
dilip kumarr
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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



 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anything specific you don't understand?? Also the code won't compile, this code will compile
 
sumit kothalikar
Ranch Hand
Posts: 91
Notepad
  • Mark post as helpful
  • send pies
  • 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.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • 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


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic