This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes scjp6 - enum question 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "scjp6 - enum question 2" Watch "scjp6 - enum question 2" New topic
Author

scjp6 - enum question 2

Srinivas Palam
Ranch Hand

Joined: Oct 20, 2005
Posts: 50
According to scjp6 certification book, below code output is WED, but I am getting compiliation error. Please help.

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. }


D:\Java>javac TestDays.java
TestDays.java:2: ';' expected
public enum Days {MON, TUe, WED};
^
TestDays.java:4: ';' expected
for (Days d: Days.values())
^
TestDays.java:6: '.class' expected
Days [] d2 = Days.values();
^
TestDays.java:7: ')' expected
System.out.println(d2[2]);
^
4 errors

D:\Java>
ayush raj
Ranch Hand

Joined: Jan 15, 2012
Posts: 60
Please use code tags. Telling you this once again . The code snippet you provided runs just fine in my JVM . Try re-compiling your code .
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

please don't repost the same question. your other post given at http://www.coderanch.com/t/593833/java-programmer-SCJP/certification/Scjp-enum is asking about the exactly same thing you are asking here. i have answered it at your other post. please check the reply there.
regards
 
GeeCON Prague 2014
 
subject: scjp6 - enum question 2