File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in enums

 
gobburi saikrishna
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers

This question is from one of mock exam


class EnumTest
{
public enum Color { RED, GREEN, BLUE };
public void foo() {
//code here
System.out.println(c);
}
public static void main(String[] args)
{
EnumTest t1=new EnumTest();
t1.foo();
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() ; c.next())
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
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why dont you try compiling it. if it succeeds then there must be some values() otherwise questn is wrong
 
Ali Khalfan
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what's the question anyway? I just see a code and and different for eachs
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic