• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Clarity about Enum???

 
Tamkin Avi
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I think the lines 6 and 7 here are just an empty loop which will do nothing...
 
Tamkin Avi
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3908
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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


Yes that's correct (since it's a loop with empty body).
 
Tamkin Avi
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic