Multiple choice java

for(Object obj: expression) { } What interface must the ?expression? implement in order for you to use it with enhanced for loop construct?

  1. Iterator

  2. Map

  3. Enumeration

  4. Iterable

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The enhanced for-loop (for-each) works with arrays and any object implementing the Iterable interface. The Iterable interface requires the implementation of an iterator() method. While Maps and Iterators are related, the expression itself must implement Iterable (or be an array).