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 Need Clarity about Enum??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Need Clarity about Enum???" Watch "Need Clarity about Enum???" New topic
Author

Need Clarity about Enum???

Tamkin Avi
Greenhorn

Joined: Nov 09, 2008
Posts: 12
Its from K&B Scjp 6 self test Chapter 1:

3. public class TestDays {
4. public enum Days { MON, TUE, WED };
5. public static void main(String[] args) {
6. for(Days d : Days.values() )
7. ;
8. Days [] d2 = Days.values();
9. System.out.println(d2[2]);
10. }
11. }


As every enum comes with a static values() method that returns an array
of the enum's values, so d2 array wiil contain MON, TUE, WED. But what is the funtionality of line 6& 7 here, please can anyone explain???
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9307
    
  17

Well I think the lines 6 and 7 here are just an empty loop which will do nothing...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Tamkin Avi
Greenhorn

Joined: Nov 09, 2008
Posts: 12
Thanks, Ankit

I also thought that, but there is also a option like "Compile time error".
So I get confused, whether those two line's syntax is correct or not??
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3838


Tamkin Avi
----
whether those two line's syntax is correct or not??


Yes that's correct (since it's a loop with empty body).


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Tamkin Avi
Greenhorn

Joined: Nov 09, 2008
Posts: 12
Thanks...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Clarity about Enum???