Which loop incurs a compile time error?

Given:

Which loop incurs a compile time error?
A. the loop starting line 11
B. the loop starting line 7
C. the loop starting line 14
D. the loop starting line 3

Download Printable PDF. VALID exam to help you PASS.

5 thoughts on “Which loop incurs a compile time error?

  1. I didn’t meant declared, but what I meant was that iter2 och iter don’t apply because they are in another scope..then “iter” cannot be found at line 14…sorry my English

  2. Definitly C, try the code I pasted. You have to focus on the scopes see the braceles “{“. The first 2 loops are in an own scope. The third and fourth are in another scope, then iter.hasnext at line 14 has already been declared, earlier

    public void foo(Object obj) {}

    public void testAll()
    {
    {
    Iterator iter = List.of(1,2,3).iterator();
    while (iter.hasNext())
    {
    foo(iter.next());
    }

    Iterator iter2 = List.of(1,2,3).iterator();
    while (iter.hasNext())
    {
    foo(iter2.next());
    }
    }
    //C
    for (Iterator iter = List.of(1,2,3).iterator(); iter.hasNext();)
    {
    foo(iter.next());
    }

    for (Iterator iter2 = List.of(1,2,3).iterator(); iter.hasNext();)
    {
    foo(iter2.next());
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.