File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt in enums...anyone please help me out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt in enums...anyone please help me out" Watch "doubt in enums...anyone please help me out" New topic
Author

doubt in enums...anyone please help me out

dilip kumarr
Greenhorn

Joined: Jan 31, 2010
Posts: 6

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

Joined: Aug 03, 2008
Posts: 9305
    
  17

Is there anything specific you don't understand?? Also the code won't compile, this code will compile


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91


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.


Thanks & Regards
Sumit Kothalikar
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

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



SCJP6.0,My blog Ranchers from Delhi
 
Consider Paul's rocket mass heater.
 
subject: doubt in enums...anyone please help me out