| Author |
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 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
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
|
 |
 |
|
|
subject: Doubt in enums
|
|
|