Rachel Glenn wrote:I have this sample question from a mock exam:
Given:
- list is a reference to a valid collection
- getCollection() returns a reference to a valid collection
Which two are valid? (Choose two.)
A. for(Object o ; list)
B. for(Object o : list.iterator())
C. for(Object o : getCollection())
D. for(Iterator i ; list.iterator() ; i.hasNext() )
E. for(Iterator i = list.iterator(); i.hasNext(); )
I understand that answer E is one of the correct options. But it seems to me that options A AND C are also valid. Can someone please explain? (Option C is the other correct option.)
A should be for(Object o : list) instead of for(Object o ; list) , so answer is CE