Multiple choice

What will be the output of the program? import java.util.*; class H { public static void main (String[] args) { Object x = new Vector().elements(); System.out.print((x instanceof Enumeration)+","); System.out.print((x instanceof Iterator)+","); System.out.print(x instanceof ListIterator); } }

  1. Prints: false,false,false

  2. Prints: false,false,true

  3. Prints: false,true,false

  4. Prints: true,false,false

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

The Vector.elements method returns an Enumeration over the elements of the vector. Vector implements the List interface and extends AbstractList so it is also possible to get an Iterator over a Vector by invoking the iterator or listIteratormethod.