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)

2. Examine the following code:

```Vector list = new Vector(10);

```

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

3. Examine the following code:

```Vector list = new Vector(5, 5);

```

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

4. Examine the following code:

```Vector list = new Vector(10);

```

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") );

5. Examine the following code:

```Vector list = new Vector(10);

```

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) ;

6. Examine the following code:

```Vector list = new Vector(10);

```

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" ) );

7. Examine the following code:

```Vector list = new Vector(10);

```

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() );

8. Examine the following code:

```Vector list = new Vector(10);

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()

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.

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