Given:
3. public class Main { 4. public static void main(String[] args) { 5. Days d1 = Days.TH; /*from w w w. ja va2s .c o m*/ 6. Days d2 = Days.M; 7. for(Days d: Days.values()) { 8. if(d.equals(Days.F)) break; 9. d2 = d; 10. } 11. System.out.println((d1 == d2)?"same old" : "newly new"); 12. } 13. enum Days {M, T, W, TH, F, SA, SU}; 14. }
What is the result?
A is correct.
All of this syntax is correct.
The for-each iterates through the enum using the values()
method to return an array.
An enum can be compared using either equals()
or ==.
An enum can be used in a ternary operator's boolean test.