Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on for loop

 
Yin Stadfield
Ranch Hand
Posts: 58
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
8. Given:

What is the result? (Choose all that apply.)
A. TUE
B. WED
C. The output is unpredictable
D. Compilation fails due to an error on line 4
E. Compilation fails due to an error on line 6
F. Compilation fails due to an error on line 8
G. Compilation fails due to an error on line 9
Answer:
® ✓ B is correct. Every enum comes with a static values() method that returns an array
of the enum's values, in the order in which they are declared in the enum.
®˚ A, C, D, E, F, and G are incorrect based on the above information. (Objective 1.3)


What's the use of the for loop here? Isn't the declaration wrong, it ends in semicolon?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33697
316
Eclipse IDE Java VI Editor
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did this question come from? We ask people to cite all mock exam or book questions. (Based on your other post, I'm guessing Chapter 1 SCJP 6 Study Guide by Kathy Sierra and Bert Bates). Please try to remember to put this info in each post.

And no, it is valid to have an empty for loop. It means loop through and don't do anything. Which doesn't accomplish much. But the exam requires you do understand that. But it could not compile if written wrong.
 
Yin Stadfield
Ranch Hand
Posts: 58
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Where did this question come from? We ask people to cite all mock exam or book questions. (Based on your other post, I'm guessing Chapter 1 SCJP 6 Study Guide by Kathy Sierra and Bert Bates). Please try to remember to put this info in each post.

And no, it is valid to have an empty for loop. It means loop through and don't do anything. Which doesn't accomplish much. But the exam requires you do understand that. But it could not compile if written wrong.


Sorry, I thought I put the name of the book here. Got it. So compiler would not be against it if a loop is empty, I just thought there's a syntax error with the loop. Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic