logo

APSU Notes


Quiz 11

Question 1

All of the items stored in an array must be of the same type.

True

Question 2

Which of the following is the correct way to declare an array of 12 integers in Java?

1
int[] number = new int[12];

Question 3

What are the indices of an array of length 5?

0, 1, 2, 3, and 4

Question 4

Given an array called items, what is the correct way of determining the number of elements in the array?

1
items.length

Question 5

If an array index is less than zero or greater than or equal to the length, Java will generate an error during runtime.

True

Question 6

An array can be used as an instance variables in a class.

True

Question 7

Given an class called Person with a public void method called display that takes no arguments, which of the following is the correct way to call display on all the elements of an array of Person objects called people?

1
2
for (int i = 0; i < people.length; i++)
    people[i].display();

Question 8

Given the following header for a method in the class Demo:

1
public static double smallest(double[] data)

Which of the following is the correct way to call this method, given an array of doubles called values?

1
double min = Demo.smallest(values);

Question 9

What is the output of the following code?

1
2
3
4
5
6
7
8
int[] arr1 = new int[5];
int[] arr2 = new int[5];
arr1[0] = 7;
arr2[0] = 9;
arr1 = arr2;
System.out.println("arr1[0] = " + arr1[0]);
arr2[0] = 12;
System.out.println("arr1[0] = " + arr1[0]);
1
2
arr1[0] = 9
arr1[0] = 12

Question 10

Arrays can be used as parameters for methods, but a method can not return an array.

False