Section 1

Preview this deck

Classes in the same package are implicitly imported into main. True or False

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (51)

Section 1

(50 cards)

Classes in the same package are implicitly imported into main. True or False

Front

False

Back

Attempting to access an array element outside of the bounds of an array, causes a(n)______. A. ArrayOutOfBoundsException B.ArrayElementOutOfBoundsException C.ArrayIndexOutOfBoundsException D. ArrayException

Front

C. ArrayIndexOutOfBoundsException

Back

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

Front

Back

The format specifier %.2f specifies that two digits of precision should be output ________ in the floating-point number A. To the right of the decimal point B. To the left of the decimal point C. Centered D. None of the above.

Front

A. To the right of the decimal point

Back

Each class you create becomes a new ________ that can be used to declare variables and create objects. A. package B. instance C. library D. type

Front

D. type

Back

Which of the following statements is false? A. Variables declared in the body of a particular method are local variables and can be used only in that method. B. A method's parameters are local variables of the method C. Every method's body is delimited by left and right braces ({ and }). D. Keyword null indicates that a method will perform a task but will not return any information

Front

D. Keyword null indicates that a method will perform a task but will not return any information

Back

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

Front

A. The value of g[3] is -1.

Back

The elements of an array of integers have a value of null before they are initialized True or False.

Front

False

Back

A(n) ________ indicates a problem that occurs while a program executes. A. syntax error B. omitted import C. missing semicolon D. exception

Front

Back

A programmer must do the following before using an array: A. B. C. D.

Front

declare then create the array

Back

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 True or False

Front

False

Back

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

Front

C. for (int i : items) System.out.prinf("%d%n", i);

Back

Which of the following statements is true? A. Each object (instance) of the class shares the class's instance variables. B. Most instance-variable declarations are preceded with the keyword public, which is an access modifier. C.Variables or methods declared with access modifier private are accessible only to methods of the class in which they're declared. D. None of the above is true.

Front

Back

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

Front

Back

A primitive-type variable does not refer to an object True or False.

Front

True

Back

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. 1

Front

C. 9

Back

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 c.length();. D. The first element of array c is specified by c[0]. A. A,C,D B. A,B,D C. C,D D. A,B,C,D

Front

B. A,B,D

Back

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

Front

A. ++arrayName[i]

Back

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

Front

Back

Exception handling helps you create ________ programs

Front

Back

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

Front

Back

Which of the following statements is false? A. Scanner method next reads characters until any white-space character is encountered, then returns the characters as a String B. To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method's arguments C. A class instance creation expression begins with keyword new and creates a new object D. A constructor is similar to a method but is called implicitly by the new operator to initialize an object's instance variables at the time the object is created

Front

B. To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method's arguments

Back

Arrays are ________. A. variable-length entities B. fixed-length entities C. data structures that contain up to 10 related data items D. used to draw a sequence of lines, or "rays"

Front

B. fixed length entities

Back

Consider integer array values, which contains 5 elements. Which statements successfully swap the contents of the array at index 3 and index 4? A. values[3] = values[4]; values[4] = values[3]; B. values[4] = values[3]; values[3] = values[4]; C. int temp = values[3]; values[3] = values[4]; values[4] = temp; D. int temp = values[3]; values[3] = values[4]; values[4] = values[3];

Front

C. int temp = values[3]; values[3] = values[4]; values[4] = temp;

Back

Which of the following statements is false? A. The method's return type specifies the type of data returned to a method's caller. B. Classes often provide public methods to allow the class's clients to set or get private instance variables; the names of these methods must begin with set or get. C. Empty parentheses following a method name indicate that the method does not require any parameters to perform its task D. When a method that specifies a return type other than voidis called and completes its task, the method must return a result to its calling method

Front

Back

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 True or False

Front

True

Back

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. True or False

Front

True

Back

Most classes you'll use in Java programs must be imported explicitly True or False

Front

True

Back

A reference to an object is required to invoke an object's methods. True or False

Front

True

Back

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

Front

Back

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

Front

A. int[] n = {1, 2, 3, 4, 5};.

Back

An exception indicates a problem that occurs while a program executes True or False

Front

True

Back

When a method terminates, the values of its local variables are _____. A. lost B. saved C. copied D. restored

Front

A. lost

Back

Constant variables also are called _______. A. write-only variables B. finals C. named constants D. all of the above

Front

Back

The new keyword should be used to create an array. True or false

Front

True

Back

Which of the following statements is false? A. By convention class names begin with an uppercase letter, and method and variable names begin with a lowercase letter. B. Instance variables exist before methods are called on an object, while the methods are executing and after the methods complete execution. C. A class normally contains one or more methods that manipulate the instance variables that belong to particular objects of the class D. Instance variables can be declared anywhere inside a class.

Front

Back

Reference-type instance variables are initialized by default to the value void. True or False

Front

False

Back

A floating-point number is a number with a decimal point. True or False

Front

True

Back

Constructors can specify parameters and return types. True or False

Front

False

Back

You can declare new classes as needed; this is one reason Java is known as a(n) ________ language. A. Portable B. Incremental C. Extensible D. Virtual

Front

Back

Which of the following statements is true? A. Local variables are automatically initialized. B.The default value for an instance variable of type String is void. C. Every instance variable has a default initial value—a value provided by Java when you do not specify the instance variable's initial value. D. The argument types in the method call must be identical to the types of the corresponding parameters in the method's declaration

Front

C. Every instance variable has a default initial value—a value provided by Java when you do not specify the instance variable's initial value.

Back

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

Front

B. Create a double array containing 14 elements

Back

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. True or False

Front

Back

A primitive-type variable does not refer to an object. True or False

Front

True

Back

If a class does not define constructors, the compiler provides a default constructor with no parameters, and the class's instance variables are initialized to C. ________. A. zero B. null C. their default values D. false

Front

C. their default values

Back

An import declaration is not required when one class in a package uses another in the same package. True or False

Front

True

Back

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

Front

B. reference

Back

Java requires a ________ call for every object that's created. A. constructor B. destructor C. parameterless D. parameterized

Front

A. constructor

Back

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 True or False

Front

Back

Constructors can specify parameters but not return types. True or False.

Front

True

Back

Section 2

(1 card)

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 True or False

Front

False

Back