Courseiva
Java Basics and SyntaxeasyMultiple ChoiceObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

A developer wants to iterate over an array of integers named 'numbers'. Which loop declaration will correctly access each element?

⚠ Common exam trap

A common mix-up: candidates confuse the for-each syntax with other languages (like Python's 'for x in list') and choose Option C, or they mistakenly think Option B accesses elements directly when it only increments a counter.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

for (int num : numbers)

It uses the enhanced for-each loop syntax, which is designed specifically for iterating over arrays and collections in Java. The colon (:) separates the element variable declaration from the array name, and each iteration assigns the next element to 'num' automatically, without needing an index or explicit bounds checking.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • for (int num : numbers)

    Why this is correct

    Correct enhanced for loop syntax.

  • for (int num = 0; num < numbers.length; num++)

    Why it's wrong here

    This is a traditional for loop, not an enhanced for loop.

  • for (int num in numbers)

    Why it's wrong here

    'in' is not Java syntax; colon is used.

  • for (int num : numbers.length)

    Why it's wrong here

    numbers.length is an int, not an array.

About these practice questions

Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.