GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on for loop 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 "Question on for loop" Watch "Question on for loop" New topic
Author

Question on for loop

Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 43

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

Joined: May 26, 2003
Posts: 30586
    
154

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 43

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!
 
GeeCON Prague 2014
 
subject: Question on for loop