Objects and Collections

Q1: 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); 
    } 
}

A Prints: false,false,false

B Prints: false,false,true

C Prints: false,true,false

D Prints: true,false,false

ANS:A - Prints: false,false,false

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 listIterator method.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.