created Jan. 06, 2000


Quiz on Vectors and Enumerations

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.


1. Declare and construct a Vector with 20 initial slots and an increment size of 5.

a.    Vector v(20) = new Vector(5)
b.    Vector v = new Vector(20)
c.    Vector[] v = new Vector(20,5)
d.    Vector v = new Vector(20, 5)

Correct Answer Is:


2. Examine the following code:

Vector list = new Vector(10);

list.addElement( new Point(5,12) );
list.addElement( new Point(15,23) );
list.addElement( new Point(62,72) );

After the code has exectued, what is the capactiy of the Vector? What is its size?

a.    3, 3
b.    3, 10
c.    10, 3
d.    10, 10

Correct Answer Is:


3. Examine the following code:

Vector list = new Vector(5, 5);

list.addElement( new Point(5,12) );
list.addElement( new Point(15,23) );
list.addElement( new Point(62,72) );
list.addElement( new Point(7,8) );
list.addElement( new Point(25,43) );
list.addElement( new Point(12,76) );

After the code has exectued, what is the capactiy of the Vector? What is its size?

a.    5, 6
b.    6, 6
c.    10, 6
d.    6, 10

Correct Answer Is:


4. Examine the following code:

Vector list = new Vector(10);

list.addElement( "Andy" );
list.addElement( "Bart" );
list.addElement( "Carl" );
list.addElement( "Doug" );
list.addElement( "Elmo" );

Which of the following will replace the element "Carl" with "Zoltan" ?

a.    list[2] = "Zoltan" ;
b.    list.setElementAt( "Zoltan", 3 );
c.    list.setElementAt( "Carl", list.indexOf("Zoltan") );
d.    list.setElementAt( "Zoltan", list.indexOf("Carl") );

Correct Answer Is:


5. Examine the following code:

Vector list = new Vector(10);

list.addElement( "Andy" );
list.addElement( "Bart" );
list.addElement( "Carl" );
list.addElement( "Doug" );
list.addElement( "Elmo" );

Which of the following will change the list so that it looks like:

Andy
Bart
Carl
Doug
Oscar
Elmo
a.    list.insertElementAt( "Oscar", 3) ;
b.    list.insertElementAt( "Oscar", 4) ;
c.    list.setElementAt( "Oscar", 3) ;
d.    list.setElementAt( "Oscar", 4) ;

Correct Answer Is:


6. Examine the following code:

Vector list = new Vector(10);

list.addElement( "Andy" );
list.addElement( "Bart" );
list.addElement( "Carl" );
list.addElement( "Doug" );
list.addElement( "Elmo" );

Which of the following will change the list so that it looks like:

Andy
Bart
Doug
Elmo
a.    list.removeElementAt( 3 );
b.    list.removeElementAt( list.elementAt( 2 ) );
c.    list.removeElementAt( list.indexOf( "Carl", 3 ) );
d.    list.removeElementAt( list.indexOf( "Carl" ) );

Correct Answer Is:


7. Examine the following code:

Vector list = new Vector(10);

list.addElement( "Andy" );
list.addElement( "Bart" );
list.addElement( "Carl" );
list.addElement( "Doug" );
list.addElement( "Elmo" );

Which of the following will change the list so that it looks like:

Andy
Bart
Carl
Doug
a.    list.removeElementAt( list.size()-1 );
b.    list.removeElementAt( 5 );
c.    list.removeElementAt( list.lastElement() );
d.    list.removeElementAt( list.capacity() );

Correct Answer Is:


8. Examine the following code:

Vector list = new Vector(10);

list.addElement( "Andy" );
list.addElement( "Bart" );
list.addElement( "Carl" );
list.addElement( "Doug" );
list.addElement( "Elmo" );

for ( Enumeration en = list.__________; en.____________; )
  System.out.println( en.___________ );

Fill in the blanks so that the list is printed.

a.    elements()       hasMoreElements()       nextElement()
b.    getElements()       hasMoreElements()       nextElement()
c.    elements()       empty()       nextElement()
d.    elements()       moreElements()       getNextElement()

Correct Answer Is:


9. A Vector object acts like:

a.    An array of primitive values.
b.    An array of references to objects of a particlar class.
c.    An array of references to objects of class Object.
d.    An array of primitive values or of object references.

Correct Answer Is:


10. What equals() method must you override for a class whose objects you expect to hold in a Vector ?

a.    public boolean equals( Object )
b.    public boolean equals( Vector )
c.    boolean equals( Object )
d.    private int equals( Object )

Correct Answer Is:



The number you got right:       Percent Correct:       Letter Grade:   

Click here (If you have just returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the "shift key" while clicking on reload to clear the old answers.)