1

Java Unit 9 Questions

1.  In general, arrays are declared to contain:

a.  Mulitple occurrences of more than one type of value or object.

b.  Multiple occurrences of one type of value or object.

c.  Only simple numeric or character data.

d.  Only object references.

2.  The punctuation marks most closely associated with arrays are:

a.  Parentheses.

b.  Curly braces.

c.  Quotation marks.

d.  Square brackets.

3.  After the size of an array is declared in code:

a.  It cannot be changed at a later time or place in the program.

b.  It can be changed at any time or place in the program.

c.  It can be changed before the end of the block in which the declaration is made.

d.  It can be changed after the end of the block in which the declaration is made.

4.  Array indexing in Java starts at:

a.  1

b.  0

c.  An arbitrary value declared when the array is created.

d.  The starting index depends on the architecture of the microprocessor.

5.  Suppose an array, myarray, is declared. Suppose also that an integer variable j is declared. If a for loop is to run through all of the elements of an array, starting with the one in the lowest position, the upper bound on the loop index j would be:

a.  j < myarray.length – 1

b.  j < myarray.length + 1

c.  j < myarray.length

d.  j <= myarray.length

6.  Here is a statement in Java: myintarray[2][4] = 24. It is:

a.  A mistake. Two pairs of consecutive brackets are not allowed.

b.  An assignment to a two dimensional array.

c.  A special operation that implements vector multiplication.

d.  A special operation that allows the elements of arrays to be exchanged.

7.  Suppose a two dimensional array is declared. Now consider this statement: int x = myintarray[0].length. It is:

a.  A mistake. You can’t use only a single set of brackets when doing anything with a two dimensional array.

b.  A technique for setting the value of all elements of the array to 0.

c.  A statement which retrieves the length of row 0 of the array.

d.  A mistake. This is a method call where the parentheses after the method name were forgotten.

8.  When passing an array as a parameter, the actual parameter should take this form:

a.  The name of the array alone.

b.  The name of the array followed by square brackets.

c.  The name of the array followed by square brackets containing the size of the array.

d.  The name of the array followed by square brackets containing 0.

9.  If an array is passed as a parameter, inside the method:

a.  The original array in the calling program is unaffected by changes to the array.

b.  The original array in the calling program is only affected by changes to the array if it was not declared static.

c.  The original array in the calling program is only affected by changes to the array if dynamic binding applies to the array.

d.  The original array in the calling program is affected by changes to the array.

10.  Consider this sequence of statements: int[] myarray = new int[3]; int[] yourarray; yourarray = myarray; The result is:

a.  Yourarray is a separate reference to myarray.

b.  Yourarray is a copy of myarray.

c.  The assignment is a syntactical error.

d.  The fact that yourarray was not given the same size as myarray is an error.

11.  Arrays:

a.  Can be declared as instance variables, but cannot be inherited.

b.  Can be declared as instance variables, but have to be declared public.

c.  Can be declared as instance variables.

d.  Cannot be declared as instance variables.

12.  The Vector class differs from a simple array in the following ways:

a.  It does not have a fixed size.

b.  It contains references to instances of the Object class.

c.  It supports methods which allow changes to all of the elements of a vector at once, as opposed to changes that are done one index value at a time.

d.  All choices are correct.