CSC 205 AB Module 2 Quiz : Arrays

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

You can use the ________ method to replace an item at a specific location in an ArrayList. a.) remove b.) replace c.) add d.) set

d.) set

Subscripting (indices) always starts with ________. a.) -1 b.) 0 c.) 1 d.) none of these

0

An ArrayList object automatically expands in size to accommodate the items stored in it. a.) True b.) False

a.) True

Arrays class is in Java.Util package. a.) True b.) False

a.) True

The ArrayList class is in the ________ package. a.) java.util b.) java.lang c.) java.arraylist d.) java.array

a.) java.util

If any int array, a, is passed as a parameter to a method, which of the following would adequately define the parameter list for the method header? a.) (int[]) b.) (int a) c.) (int[] a) d.) (int a[]) e.) (a[])

c.) (int[] a) The parameter is defined much as the variable is originally declared, as type parameter name. Here, the type is int[] and the parameter is a.

When an individual element of an array is passed to a method ________. a.) the method does not have access to the original array b.) a reference to the array is passed c.) it is passed like any other variable d.) All of these are true.

a.) the method does not have access to the original array

When an array of objects is declared but not initialized, the array values are set to 0. a.) True b.) False

b.) False

What does the following statement do?double[] array1 = new double[10]; a.) It declares array1 to be a reference to an array of double values. b.) It does all of these. c.) It creates an instance of an array of ten double values. d.) It will allow valid subscripts in the range of 0 through 9.

b.) It does all of these.

Which of the following for loops is valid, given the following declaration?String[] names = {"abc", "def", "ghi", "jkl"}; a.) for (int i = 0; i < names.length; i++) System.out.println(names[i].length); b.) for (int i = 0; i < names.length; i++) System.out.println(names[i].length()); c.) for (int i = 0; i < names.length(); i++) System.out.println(names[i].length); d.) for (int i = 0; i < names.length(); i++) System.out.println(names[i].length());

b.) for (int i = 0; i < names.length; i++) System.out.println(names[i].length());

The ________ method removes an item from an ArrayList at a specific index. a.) pop b.) remove c.) clear d.) deleteAt

b.) remove

If a and b are both int arrays, then a = b wil a.) copy all elements of a into b b.) return true if each corresponding element of b is equal to each corresponding element of a (that is, if a[0] is equal to b[0], a[1] is equal to b[1] and so forth) and return false otherwise c.) return true if a and b are aliases and return false otherwise d.) create an alias e.) copy the zero element of b into the zero element of a

d.) create an alias The = is an assignment operator. If the two variables are primitives, than the left-hand variable gets a copy of the right-hand variable. However, since a and b are arrays, the reference variable a is set to the reference variable b, resulting in both a and b referencing the same array in memory, or they are now aliases of each other.

It is common practice to use a ________ variable as a size declarator. a.) reference b.) static c.) boolean d.) final

d.) final

Each array in Java has a public field named ________ that contains the number of elements in the array. a.) capacity b.) size c.) limit d.) length

d.) length

When an array is passed to a method ________. a.) the method has direct access to the original array b.) it is passed just as any other object would be passed c.) a reference to the array is passed d.) All of these are true

d.) All of these are true

Which of the following statements is(are) true about this code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE]; a.) It will allow valid subscripts in the range of 0 through 9. b.) It creates an instance of an array of ten long values. c.) It declares array1 to be a reference to an array of long values. d.) All of these are true.

d.) All of these are true.

What will be the results after the following code is executed? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8; a.) a = 8 b.) a = 13 c.) a = 10 d.) a = 5

d.) a = 5

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"}; a.) a reference to the String object containing "def" b.) "def" c.) "ghi" d.) a reference to the String object containing "ghi"

d.) a reference to the String object containing "ghi"

In memory, an array of String objects ________. a.) is compressed to four bytes for each element b.) consists of elements, each of which is a reference to a String object c.) must be initialized when the array is declared d.) consists of an array of references to String objects

d.) consists of an array of references to String objects

Which of the following is a correct method header for receiving a one-dimensional array as an argument? a.) public static void passMyArray(int[1, 2]) b.) public static void passMyArray(int[],int[] myArray) c.) public static void passMyArray[1]) d.) public static void passMyArray(int[] myArray)

d.) public static void passMyArray(int[] myArray)


Set pelajaran terkait

Technical Support Fundaments. Week 6: Troubleshooting and Customer Service

View Set

Chapter 15-Cost and Profitability Analysis

View Set

Daily Trigonometry - Find the value of the missing angle / side

View Set

Abnormal Psychology Chapters 4, 5 & 6

View Set

makromolekyler, molekyler (klar)

View Set

Fundamentals, (ch, 19 Documenting and Reporting)

View Set