Home / Java Programming / Objects and Collections :: Discussion

Discussion :: Objects and Collections

  1. What will be the output of the program?

      import java.util.*;
      class I
      {    
           public static void main (String[] args)  
           {         
               Object i = new ArrayList().iterator();     
               System.out.print((i instanceof List)+",");          
               System.out.print((i instanceof Iterator)+",");          
               System.out.print(i instanceof ListIterator);  
        }  
    }
    

  2. A.

    Prints: false, false, false

    B.

    Prints: false, false, true

    C.

    Prints: false, true, false

    D.

    Prints: false, true, true

    View Answer

    Workspace

    Answer : Option C

    Explanation :

    The iterator() method returns an iterator over the elements in the list in proper sequence, it doesn't return a List or a ListIterator object.

    A ListIterator can be obtained by invoking the listIterator method.


Be The First To Comment