File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in enums 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 "Doubt in enums" Watch "Doubt in enums" New topic

Doubt in enums

gobburi saikrishna
Ranch Hand

Joined: Jan 21, 2008
Posts: 52
Hello ranchers

This question is from one of mock exam

class EnumTest
public enum Color { RED, GREEN, BLUE };
public void foo() {
//code here
public static void main(String[] args)
EnumTest t1=new EnumTest();;
System.out.println("Hello World!");
Which code inserted at line 14 causes the foo method to print RED,
GREEN, and BLUE? Answers
A. for( Color c : Color.values())
B. for( Color c = RED; c <= BLUE; c++)
C. for( Color c; c.hasNext() ;
D. for( Color c = Color[0]; c <= Color[2]; c++)
E. for( Color c = Color.RED; c <= Color.BLUE; c++)

here answer is A, my doubt is we dint define or declared values() method, in java api enum class the method is valueOf(), can anyone please explain me how is answer A
[ February 26, 2008: Message edited by: gobburi saikrishna ]
Nadeem Khan
Ranch Hand

Joined: Nov 27, 2007
Posts: 108
Why dont you try compiling it. if it succeeds then there must be some values() otherwise questn is wrong

<i>If there were no Exceptions (not Errors!), Life would have kinda sucked!!</i>
Ali Khalfan
Ranch Hand

Joined: Nov 03, 2007
Posts: 126
what's the question anyway? I just see a code and and different for eachs
I agree. Here's the link:
subject: Doubt in enums
It's not a secret anymore!