Deck 6: Arrays and Arraylists

Full screen (f)
exit full mode
Question
Consider the class below:
Public class Test
{
Public static void main(String[] args)
{
Int[] a = {99, 22, 11, 3, 11, 55, 44, 88, 2, -3};
Int result = 0;
For (int i = 0; i <
A) Result is: 280.

A)length; i++) {
If (a[i] > 30)
Result += a[i];
}
System.out.printf("Result is: %d%n", result);
}
}
The output of this Java program will be:
B) Result is: 286.
C) Result is: 154.
D) Result is: 332.
Use Space or
up arrow
down arrow
to flip the card.
Question
A(n) ________ indicates a problem that occurs while a program executes.

A) syntax error
B) omitted import
C) missing semicolon
D) exception
Question
Which expression adds 1 to the element of array arrayName at index i?

A) ++arrayName[i].
B) arrayName++[i].
C) arrayName[i++].
D) None of the above.
Question
Which flag in a format specifier indicates that values with fewer digits than the field width should begin with a leading 0?

A) p.
B) l.
C) w.
D) 0.
Question
Consider the array:
S[0] = 7
S[1] = 0
S[2] = -12
S[3] = 9
S[4] = 10
S[5] = 3
S[6] = 6
The value of s[s[6] - s[5]] is:

A) 0.
B) 3.
C) 9.
D) 0.
Question
Invalid possibilities for array indices include .

A) Positive integers.
B) Negative integers.
C) Zero.
D) None of the above.
Question
Consider the code segment below. Which of the following statements is false?
Int[] g;
G = new int[23];

A) The value of g[3] is -1.
B) The first statement declares an array reference.
C) The second statement creates the array.
D) g is a reference to an array of integers.
Question
A programmer must do the following before using an array:

A) declare then reference the array.
B) create then declare the array.
C) create then reference the array.
D) declare then create the array.
Question
Constant variables also are called .

A) write-only variables
B) finals
C) named constants
D) All of the above
Question
Which of the following statements is false?

A) A reference to an object is required to invoke an object's methods.
B) A primitive-type variable does not refer to an object.
C) Reference-type instance variables are initialized by default to the value void.
D) A primitive-type variable cannot be used to invoke a method.
Question
Types in Java are divided into two categories. The primitive types are boolean, byte, char, short, int, long, float and double. All other types are ________ types.

A) static
B) reference
C) declared
D) source
Question
Which of the following initializer lists would correctly set the elements of array n?

A) int[] n = {1, 2, 3, 4, 5};.
B) array n[int] = {1, 2, 3, 4, 5};.
C) int n[5] = {1; 2; 3; 4; 5};.
D) int n = new int(1, 2, 3, 4, 5);.
Question
Attempting to access an array element outside of the bounds of an array, causes a(n) .

A) ArrayOutOfBoundsException.
B) ArrayElementOutOfBoundsException.
C) ArrayIndexOutOfBoundsException.
D) ArrayException.
Question
What do the following statements do?
Double[] array;
Array = new double[14];

A) Create a double array containing 13 elements.
B) Create a double array containing 14 elements.
C) Create a double array containing 15 elements.
D) Declare but do not create a double array.
Question
Which of the following statements about arrays are true?
A) An array is a group of variables containing values that all have the same type.
B) Elements are located by index.
C) The length of an array c is determined by the expression

A) A, C, D.
B) A, B, D.
C) C, D.
C)length();. D. The zeroth element of array c is specified by c[0].
D) A, B, C, D.
Question
Reference-type variables (called references) store ________ in memory.

A) the value of an object
B) a copy of an object
C) the location of an object
D) the size of an object
Question
Which of the following statements is false?

A) An exception indicates a problem that occurs while a program executes.
B) Exception handling enables you to create fault-tolerant programs that can resolve (or handle) exceptions-in many cases, this allows a program to continue executing as if no problems were encountered.
C) The catch block contains the code that might throw an exception, and the try block contains the code that handles the exception if one occurs.
D) Inside the catch block, you can use the parameter's identifier to interact with a caught exception object.
Question
Which of the following statements is false?

A) A primitive-type variable can store exactly one value of its declared type at a time.
B) Primitive-type instance variables are initialized by default.
C) Variables of types byte, char, short, int, long, float and double are initialized to 0.
D) Variables of type boolean are initialized to true.
Question
Which of the following statements about creating arrays and initializing their elements is false?

A) The new keyword should be used to create an array.
B) When an array is created with operator new, the number of elements must be placed in square brackets following the type of element being stored.
C) The elements of an array of integers have a value of null before they are initialized.
D) A for loop is commonly used to set the values of the elements of an array.
Question
Which of the following will not produce a compiler error?

A) Changing the value of a constant after it is initialized.
B) Changing the value at a given index of an array after it is created.
C) Using a final variable before it is initialized.
D) All of the above will produce compiler errors.
Question
Which of the following tasks cannot be performed using an enhanced for loop?

A) Calculating the product of all the values in an array.
B) Displaying all even element values in an array.
C) Comparing the elements in an array to a specific value.
D) Incrementing the value stored in each element of the array.
Question
Assume array items contains the integer values 0, 2, 4, 6 and 8. Which of the following uses the enhanced for loop to display each value in array items?

A) for (int i = 0; i < items.length; i++)
System.out.prinf("%d%n", items[i]);
B) for (int i : items)
System.out.prinf("%d%n", items[i]);
C) for (int i : items)
System.out.prinf("%d%n", i);
D) for (int i = 0 : items.length)
System.out.prinf("%d%n", items[i]);
Question
The preferred way to traverse a two-dimensional array is to use .

A) a do while statement.
B) a for statement.
C) two nested for statements.
D) three nested for statements.
Question
In Java, multidimensional arrays ________.

A) are not directly supported.
B) are implemented as arrays of arrays.
C) are often used to represent tables of values.
D) All of the above.
Question
Which set of statements totals the items in each row of two-dimensional array items, and displays each row's total?

A) for (int row = 0; row < items.length; row++)
{
Int total = 0;
For (int column = 0; column < items[row].length; column++)
Total += items[row][column];
System.out.printf("Row %d's total is %d%n", row, total);
}
B) int total = 0;
For (int row = 0; row < items.length; row++)
{
For (int column = 0; column < items[row].length; column++)
Total += items[row][column];
System.out.printf("Row %d's total is %d%n", row, total);
}
C) int total = 0;
For (int row = 0; row < items.length; row++)
{
For (int column = 0; column < items[column].length; column++)
Total += items[row][column];
System.out.printf("Row %d's total is %d%n", row, total);
}
D) for (int row = 0; row < items.length; row++)
{
Int total = 0;
For (int column = 0; column < items[column].length; column++)
Total += items[row][column];
System.out.printf("Row %d's total is %d%n", row, total);
}
Question
Which of the following sets of statements creates a multidimensional array with 3 rows, where the first row contains 1 value, the second row contains 4 items and the final row contains 2 items?

A) int[][] items;
Items = new int[3][?];
Items[0] = new int[1];
Items[1] = new int[4];
Items[2] = new int[2];
B) int[][] items;
Items = new int[3][];
Items[0] = new int[1];
Items[1] = new int[4];
Items[2] = new int[2];
C) int[][] items;
Items = new int[?][?];
Items[0] = new int[1];
Items[1] = new int[4];
Items[2] = new int[2];
D) int[][] items;
Items[0] = new int[1];
Items[1] = new int[4];
Items[2] = new int[2];
Question
When you pass an array or an individual array element of a reference type to a method, the called method receives ________. When you pass an individual element of a primitive type, the called method receives ________.

A) a copy of the element's reference, a copy of the element's reference
B) a copy of the element's value, a copy of the element's reference
C) a copy of the element's value, a copy of the element's value
D) a copy of the element's reference, a copy of the element's value
Question
An argument type followed by a(n) in a method's parameter list indicates that the method receives a variable number of arguments of that particular type.

A) square brackets ([])
B) ellipsis (...)
C) varargs keyword
D) All of the above are acceptable to indicate a variable number of arguments.
Question
Which statement correctly passes the array items to method takeArray? Array items contains 10 elements.

A) takeArray(items[]).
B) takeArray(items).
C) takeArray(items[9]).
D) Arrays cannot be passed to methods-each item must be sent to the method separately.
Question
Which of the following statements is false?

A) When an argument is passed by reference, the called method can access the argument's value in the caller directly but cannot modify it.
B) All arguments in Java are passed by value.
C) To pass an individual array element to a method, use the indexed name of the array.
D) To pass an object reference to a method, simply specify in the method call the name of the variable that refers to the object.
Question
Which of the following statements creates a multidimensional array with 3 rows, where the first row contains 1 element, the second row contains 4 elements and the final row contains 2 elements?

A) int[][] items = {{1, null, null, null}, {2, 3, 4, 5}, {6, 7, null, null}};
B) int[][] items = {{1}, {2, 3, 4, 5}, {6, 7}};
C) int[][] items = {{1}, {2, 3, 4, 5}, {6, 7}, {});
D) int[][] items = {{1}, {4}, {2}};
Question
Which of the following statements is true?

A) The catch block contains the code that might throw an exception.
B) The try block contains the code that handles the exception if one occurs.
C) You can have many catch blocks to handle different types of exceptions.
D) When a try block terminates, any variables declared in the try block are preserved.
Question
Exception handling helps you create ________ programs.

A) high-performance
B) logic-error-free
C) fault-tolerant
D) compilation-error-free
Question
An array with m rows and n columns is not ________.
A) an m-by-n array.
B) an n-by-m array.
C) a two-dimensional array.
D) a dual-transcripted array.

A) A and C.
B) A and D.
C) B and D.
D) B and C.
Question
Which statement below initializes array items to contain 3 rows and 2 columns?

A) int[][] items = {{2, 4}, {6, 8}, {10, 12}};
B) int[][] items = {{2, 6, 10}, {4, 8, 12}};
C) int[][] items = {2, 4}, {6, 8}, {10, 12};
D) int[][] items = {2, 6, 10}, {4, 8, 12};
Question
When an argument is passed by reference, ________.

A) a copy of the argument's value is passed to the called method
B) changes to the argument do not affect the original variable's value in the caller
C) the called method can access the argument's value in the caller directly and modify that data
D) the original value is removed from memory
Question
6.2 Q1 Which of the following statements is false?

A) A catch block declares a type and an exception parameter name.
B) Inside the catch block, you can use the parameter's name to interact with a caught exception object.
C) When a program is executed, array element indices are checked for validity-all indices must be greater than 0 and less than or equal to the length of the array.
D) If an attempt is made to use an invalid index to access an element, an ArrayIndexOutOfBoundsException exception occurs.
Question
In array items, which expression below accesses the value at row 3 and column 4?

A) items[3].[4]
B) items[3[4]]
C) items[3][4]
D) items[3, 4]
Question
Consider array items, which contains the values 0, 2, 4, 6 and 8. If method changeArray is called with the method call changeArray(items, items[2]), what values are stored in items after the method has finished executing?
Public static void changeArray(int[] passedArray, int value)
{
PassedArray[value] = 12;
Value = 5;
}

A) 0, 2, 5, 6, 12.
B) 0, 2, 12, 6, 8.
C) 0, 2, 4, 6, 5.
D) 0, 2, 4, 6, 12.
Question
For the array that was the correct answer in the previous question, what is the value returned by items[1][0]?

A) 4.
B) 8.
C) 12.
D) 6.
Question
Which of the following statements about an arc is false?

A) An arc is a section of an oval.
B) The sweep is the amount of arc to cover.
C) Method drawArc draws the edges of an arc.
D) The fillArc method draws an oval, with the section that is an arc filled in.
Question
Class Arrays methods sort, binarySearch, equals and fill are overloaded for primitive-type arrays and Object arrays. In addition, methods __________ and __________ are overloaded with generic versions.

A) sort, binarySearch.
B) sort, fill.
C) binarySearch, equals.
D) binarySearch, fill.
Question
Which of the following is false?

A) The size of an ArrayList can be determined via its length instance variable.
B) The size of an ArrayList can be determined via its size method.
C) You can add a new item to the end of an ArrayList with its add method.
C) You can get an item from a specified index in an ArrayList with its get method.
Question
Class ________ represents a dynamically resizable array-like data structure.

A) Array
B) ArrayList
C) Arrays
D) None of the above.
Question
Which command below runs TestProgram, and passes in the values files.txt and 3?

A) java TestProgram files.txt 3.
B) java TestProgram files.txt, 3.
C) java TestProgram "files.txt", "3".
D) None of the above.
Question
Which method call converts the value in variable stringVariable to an integer?

A) Convert.toInt(stringVariable)
B) Convert.parseInt(stringVariable)
C) Integer.parseInt(stringVariable)
D) Integer.toInt(stringVariable)
Question
Class Arrays provides method __________ for comparing arrays to determine whether they have the same contents.

A) compare
B) compares
C) equal
D) equals
Question
Which method sets the background color of a JPanel?

A) setBack.
B) setBackground.
C) setBackgroundColor.
D) setColor.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/48
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 6: Arrays and Arraylists
1
Consider the class below:
Public class Test
{
Public static void main(String[] args)
{
Int[] a = {99, 22, 11, 3, 11, 55, 44, 88, 2, -3};
Int result = 0;
For (int i = 0; i <
A) Result is: 280.

A)length; i++) {
If (a[i] > 30)
Result += a[i];
}
System.out.printf("Result is: %d%n", result);
}
}
The output of this Java program will be:
B) Result is: 286.
C) Result is: 154.
D) Result is: 332.
B
2
A(n) ________ indicates a problem that occurs while a program executes.

A) syntax error
B) omitted import
C) missing semicolon
D) exception
D
3
Which expression adds 1 to the element of array arrayName at index i?

A) ++arrayName[i].
B) arrayName++[i].
C) arrayName[i++].
D) None of the above.
A
4
Which flag in a format specifier indicates that values with fewer digits than the field width should begin with a leading 0?

A) p.
B) l.
C) w.
D) 0.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
5
Consider the array:
S[0] = 7
S[1] = 0
S[2] = -12
S[3] = 9
S[4] = 10
S[5] = 3
S[6] = 6
The value of s[s[6] - s[5]] is:

A) 0.
B) 3.
C) 9.
D) 0.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
6
Invalid possibilities for array indices include .

A) Positive integers.
B) Negative integers.
C) Zero.
D) None of the above.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
7
Consider the code segment below. Which of the following statements is false?
Int[] g;
G = new int[23];

A) The value of g[3] is -1.
B) The first statement declares an array reference.
C) The second statement creates the array.
D) g is a reference to an array of integers.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
8
A programmer must do the following before using an array:

A) declare then reference the array.
B) create then declare the array.
C) create then reference the array.
D) declare then create the array.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
9
Constant variables also are called .

A) write-only variables
B) finals
C) named constants
D) All of the above
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
10
Which of the following statements is false?

A) A reference to an object is required to invoke an object's methods.
B) A primitive-type variable does not refer to an object.
C) Reference-type instance variables are initialized by default to the value void.
D) A primitive-type variable cannot be used to invoke a method.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
11
Types in Java are divided into two categories. The primitive types are boolean, byte, char, short, int, long, float and double. All other types are ________ types.

A) static
B) reference
C) declared
D) source
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
12
Which of the following initializer lists would correctly set the elements of array n?

A) int[] n = {1, 2, 3, 4, 5};.
B) array n[int] = {1, 2, 3, 4, 5};.
C) int n[5] = {1; 2; 3; 4; 5};.
D) int n = new int(1, 2, 3, 4, 5);.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
13
Attempting to access an array element outside of the bounds of an array, causes a(n) .

A) ArrayOutOfBoundsException.
B) ArrayElementOutOfBoundsException.
C) ArrayIndexOutOfBoundsException.
D) ArrayException.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
14
What do the following statements do?
Double[] array;
Array = new double[14];

A) Create a double array containing 13 elements.
B) Create a double array containing 14 elements.
C) Create a double array containing 15 elements.
D) Declare but do not create a double array.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following statements about arrays are true?
A) An array is a group of variables containing values that all have the same type.
B) Elements are located by index.
C) The length of an array c is determined by the expression

A) A, C, D.
B) A, B, D.
C) C, D.
C)length();. D. The zeroth element of array c is specified by c[0].
D) A, B, C, D.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
16
Reference-type variables (called references) store ________ in memory.

A) the value of an object
B) a copy of an object
C) the location of an object
D) the size of an object
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following statements is false?

A) An exception indicates a problem that occurs while a program executes.
B) Exception handling enables you to create fault-tolerant programs that can resolve (or handle) exceptions-in many cases, this allows a program to continue executing as if no problems were encountered.
C) The catch block contains the code that might throw an exception, and the try block contains the code that handles the exception if one occurs.
D) Inside the catch block, you can use the parameter's identifier to interact with a caught exception object.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following statements is false?

A) A primitive-type variable can store exactly one value of its declared type at a time.
B) Primitive-type instance variables are initialized by default.
C) Variables of types byte, char, short, int, long, float and double are initialized to 0.
D) Variables of type boolean are initialized to true.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following statements about creating arrays and initializing their elements is false?

A) The new keyword should be used to create an array.
B) When an array is created with operator new, the number of elements must be placed in square brackets following the type of element being stored.
C) The elements of an array of integers have a value of null before they are initialized.
D) A for loop is commonly used to set the values of the elements of an array.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following will not produce a compiler error?

A) Changing the value of a constant after it is initialized.
B) Changing the value at a given index of an array after it is created.
C) Using a final variable before it is initialized.
D) All of the above will produce compiler errors.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following tasks cannot be performed using an enhanced for loop?

A) Calculating the product of all the values in an array.
B) Displaying all even element values in an array.
C) Comparing the elements in an array to a specific value.
D) Incrementing the value stored in each element of the array.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
22
Assume array items contains the integer values 0, 2, 4, 6 and 8. Which of the following uses the enhanced for loop to display each value in array items?

A) for (int i = 0; i < items.length; i++)
System.out.prinf("%d%n", items[i]);
B) for (int i : items)
System.out.prinf("%d%n", items[i]);
C) for (int i : items)
System.out.prinf("%d%n", i);
D) for (int i = 0 : items.length)
System.out.prinf("%d%n", items[i]);
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
23
The preferred way to traverse a two-dimensional array is to use .

A) a do while statement.
B) a for statement.
C) two nested for statements.
D) three nested for statements.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
24
In Java, multidimensional arrays ________.

A) are not directly supported.
B) are implemented as arrays of arrays.
C) are often used to represent tables of values.
D) All of the above.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
25
Which set of statements totals the items in each row of two-dimensional array items, and displays each row's total?

A) for (int row = 0; row < items.length; row++)
{
Int total = 0;
For (int column = 0; column < items[row].length; column++)
Total += items[row][column];
System.out.printf("Row %d's total is %d%n", row, total);
}
B) int total = 0;
For (int row = 0; row < items.length; row++)
{
For (int column = 0; column < items[row].length; column++)
Total += items[row][column];
System.out.printf("Row %d's total is %d%n", row, total);
}
C) int total = 0;
For (int row = 0; row < items.length; row++)
{
For (int column = 0; column < items[column].length; column++)
Total += items[row][column];
System.out.printf("Row %d's total is %d%n", row, total);
}
D) for (int row = 0; row < items.length; row++)
{
Int total = 0;
For (int column = 0; column < items[column].length; column++)
Total += items[row][column];
System.out.printf("Row %d's total is %d%n", row, total);
}
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following sets of statements creates a multidimensional array with 3 rows, where the first row contains 1 value, the second row contains 4 items and the final row contains 2 items?

A) int[][] items;
Items = new int[3][?];
Items[0] = new int[1];
Items[1] = new int[4];
Items[2] = new int[2];
B) int[][] items;
Items = new int[3][];
Items[0] = new int[1];
Items[1] = new int[4];
Items[2] = new int[2];
C) int[][] items;
Items = new int[?][?];
Items[0] = new int[1];
Items[1] = new int[4];
Items[2] = new int[2];
D) int[][] items;
Items[0] = new int[1];
Items[1] = new int[4];
Items[2] = new int[2];
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
27
When you pass an array or an individual array element of a reference type to a method, the called method receives ________. When you pass an individual element of a primitive type, the called method receives ________.

A) a copy of the element's reference, a copy of the element's reference
B) a copy of the element's value, a copy of the element's reference
C) a copy of the element's value, a copy of the element's value
D) a copy of the element's reference, a copy of the element's value
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
28
An argument type followed by a(n) in a method's parameter list indicates that the method receives a variable number of arguments of that particular type.

A) square brackets ([])
B) ellipsis (...)
C) varargs keyword
D) All of the above are acceptable to indicate a variable number of arguments.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
29
Which statement correctly passes the array items to method takeArray? Array items contains 10 elements.

A) takeArray(items[]).
B) takeArray(items).
C) takeArray(items[9]).
D) Arrays cannot be passed to methods-each item must be sent to the method separately.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
30
Which of the following statements is false?

A) When an argument is passed by reference, the called method can access the argument's value in the caller directly but cannot modify it.
B) All arguments in Java are passed by value.
C) To pass an individual array element to a method, use the indexed name of the array.
D) To pass an object reference to a method, simply specify in the method call the name of the variable that refers to the object.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following statements creates a multidimensional array with 3 rows, where the first row contains 1 element, the second row contains 4 elements and the final row contains 2 elements?

A) int[][] items = {{1, null, null, null}, {2, 3, 4, 5}, {6, 7, null, null}};
B) int[][] items = {{1}, {2, 3, 4, 5}, {6, 7}};
C) int[][] items = {{1}, {2, 3, 4, 5}, {6, 7}, {});
D) int[][] items = {{1}, {4}, {2}};
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following statements is true?

A) The catch block contains the code that might throw an exception.
B) The try block contains the code that handles the exception if one occurs.
C) You can have many catch blocks to handle different types of exceptions.
D) When a try block terminates, any variables declared in the try block are preserved.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
33
Exception handling helps you create ________ programs.

A) high-performance
B) logic-error-free
C) fault-tolerant
D) compilation-error-free
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
34
An array with m rows and n columns is not ________.
A) an m-by-n array.
B) an n-by-m array.
C) a two-dimensional array.
D) a dual-transcripted array.

A) A and C.
B) A and D.
C) B and D.
D) B and C.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
35
Which statement below initializes array items to contain 3 rows and 2 columns?

A) int[][] items = {{2, 4}, {6, 8}, {10, 12}};
B) int[][] items = {{2, 6, 10}, {4, 8, 12}};
C) int[][] items = {2, 4}, {6, 8}, {10, 12};
D) int[][] items = {2, 6, 10}, {4, 8, 12};
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
36
When an argument is passed by reference, ________.

A) a copy of the argument's value is passed to the called method
B) changes to the argument do not affect the original variable's value in the caller
C) the called method can access the argument's value in the caller directly and modify that data
D) the original value is removed from memory
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
37
6.2 Q1 Which of the following statements is false?

A) A catch block declares a type and an exception parameter name.
B) Inside the catch block, you can use the parameter's name to interact with a caught exception object.
C) When a program is executed, array element indices are checked for validity-all indices must be greater than 0 and less than or equal to the length of the array.
D) If an attempt is made to use an invalid index to access an element, an ArrayIndexOutOfBoundsException exception occurs.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
38
In array items, which expression below accesses the value at row 3 and column 4?

A) items[3].[4]
B) items[3[4]]
C) items[3][4]
D) items[3, 4]
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
39
Consider array items, which contains the values 0, 2, 4, 6 and 8. If method changeArray is called with the method call changeArray(items, items[2]), what values are stored in items after the method has finished executing?
Public static void changeArray(int[] passedArray, int value)
{
PassedArray[value] = 12;
Value = 5;
}

A) 0, 2, 5, 6, 12.
B) 0, 2, 12, 6, 8.
C) 0, 2, 4, 6, 5.
D) 0, 2, 4, 6, 12.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
40
For the array that was the correct answer in the previous question, what is the value returned by items[1][0]?

A) 4.
B) 8.
C) 12.
D) 6.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
41
Which of the following statements about an arc is false?

A) An arc is a section of an oval.
B) The sweep is the amount of arc to cover.
C) Method drawArc draws the edges of an arc.
D) The fillArc method draws an oval, with the section that is an arc filled in.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
42
Class Arrays methods sort, binarySearch, equals and fill are overloaded for primitive-type arrays and Object arrays. In addition, methods __________ and __________ are overloaded with generic versions.

A) sort, binarySearch.
B) sort, fill.
C) binarySearch, equals.
D) binarySearch, fill.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
43
Which of the following is false?

A) The size of an ArrayList can be determined via its length instance variable.
B) The size of an ArrayList can be determined via its size method.
C) You can add a new item to the end of an ArrayList with its add method.
C) You can get an item from a specified index in an ArrayList with its get method.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
44
Class ________ represents a dynamically resizable array-like data structure.

A) Array
B) ArrayList
C) Arrays
D) None of the above.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
45
Which command below runs TestProgram, and passes in the values files.txt and 3?

A) java TestProgram files.txt 3.
B) java TestProgram files.txt, 3.
C) java TestProgram "files.txt", "3".
D) None of the above.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
46
Which method call converts the value in variable stringVariable to an integer?

A) Convert.toInt(stringVariable)
B) Convert.parseInt(stringVariable)
C) Integer.parseInt(stringVariable)
D) Integer.toInt(stringVariable)
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
47
Class Arrays provides method __________ for comparing arrays to determine whether they have the same contents.

A) compare
B) compares
C) equal
D) equals
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
48
Which method sets the background color of a JPanel?

A) setBack.
B) setBackground.
C) setBackgroundColor.
D) setColor.
Unlock Deck
Unlock for access to all 48 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 48 flashcards in this deck.