CS Exam 3
Which symbol indicates that a member is private a UML diagram? 1. - 2. * 3. # 4. +
-
By default, Java initializes array elements to __________ 1. 0 2. 100 3. -1 4. 1
0
Subscripting always starts with __________. 1. 0 2. 1 3. -1 4. none of these
0
Given the following code, what will be the value of finalAmount when it is displayed? public class Order { private int orderNum; private double orderAmount; private double orderDiscount; public Order(int orderNumber, double orderAmt, double orderDisc) { orderNum = orderNumber; orderAmount = orderAmt; orderDiscount = orderDisc; } public double finalOrderTotal() { return orderAmount - orderAmount * orderDiscount; } } public class CustomerOrder { public static void main(String[] args) { Order order; int orderNumber = 1234; double orderAmt = 580.00; double orderDisc = .1; order = new Order(orderNumber, orderAmt, orderDisc); double finalAmount = order.finalOrderTotal(); System.out.printf("Final order amount =$%,.2f\n", finalAmount); } } 1. 528.00 2. 580.00 3. 522.00 4. There is no value because the object, order, has not been created.
522.00
What will be the value of x[8] after the following code is executed? final int SUB = 12; int[] x = new int[SUB]; int y = 20; for(int i = 0; i < SUB; i++) { x[i] = y; y += 5; } 1. 50 2. 55 3. 60 4. 65
60
What is the value of scores[2][3] in the following array? int[][] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} }; 1. 95 2. 84 3. 94 4. 93
94
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"}; 1. a reference to the String object containing "ghi 2. "ghi" 3. a reference to the String object containing "def" 4. "def"
a reference to the String object containing "ghi"
A ragged array is __________. 1. a two-dimensional array where the rows have different numbers of columns 2. a one-dimensional array for which the number of elements is unknown 3. a two-dimensional array for which the number of rows is unknown 4. a partially initialized two- dimensional array of ranged values
a two-dimensional array where the rows have different numbers of columns
The following statement is an example of __________. import java.util.*; 1. an explicit import statement 2. an unconditional import statement 3. a wildcard import statement 4. a conditional import statement
a wildcard import statement
A class's responsibilities include __________. 1. the things a class is responsible for knowing 2. the things a class is responsible for doing 3. both of these 4. neither of these
both of these
It is common practice in object-oriented programming to make all of a class's __________. 1. fields private 2. methods private 3. fields public 4. fields and methods public
fields private
It is common practice to use a __________ variable as a size declarator. 1. static 2. reference 3. final 4. boolean
final
If numbers is a two-dimensional int array that has been initialized and total is an int that has been set to 0, which of the following will sum all the elements in the array? 1. for (int row = 1; row < numbers.length; row++) { for (int col = 1; col < numbers.length; col++) total += numbers[row][col]; } 2. for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers.length; col++) total += numbers[row][col]; } 3. for (int row = 0; row < numbers[row].length; row++) { for (int col = 0; col < numbers.length; col++) total += numbers[row][col]; } 4. for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }
for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }
A constructor __________. 1. always accepts two arguments 2. has the return type of void 3. has the same name as the class 4. always has a private access specifier
has the same name as the class
Overloading means that multiple methods in the same class __________. 1. have the same name but different return types 2. have different names but the same parameter list 3. have the same name but different parameter lists 4. perform the same function
have the same name but different parameter lists
In Java, you do not use the new operator when you use a(n) ____________. 1. array size declarator 2. initialization list 3. two-dimensional array 4. any of these
initialization list
Another term for an object of a class is a(n) __________. 1. access specifier 2. instance 3. member 4. method
instance
Methods that operate on an object's fields are called __________. 1. instance methods 2. instance variables 3. private methods 4. public methods
instance methods
Methods that operate on an object's fields are called __________. 1. instance variables 2. instance methods 3. public methods 4. private methods
instance methods
Which of the following is a valid declaration for a ragged array with five rows but no columns? 1. int[][] ragged = new int[5]; 2. int[][] ragged = new int[][5]; 3. int[][] ragged = new int[5][]; 4. int[] ragged = new int[5];
int[][] ragged = new int[5][];
A search algorithm __________. 1. arranges elements in ascending order 2. arranges elements in descending order 3. is used to locate a specific item in a collection of data 4. is rarely used with arrays
is used to locate a specific item in a collection of data
The __________ package is automatically imported into all Java programs. 1. java.java 2. java.default 3. java.util 4. java.lang
java.lang
The ArrayList class is in the __________ package. 1. java.arraylist 2. java.lang 3. java.array 4. java.util
java.util
Each array in Java has a public field named __________ that contains the number of elements in the array. 1. size 2. capacity 3. length 4. limit
length
A reference variable stores a(n) __________. 1. binary encoded decimal 2. memory address 3. object 4. string
memory address
Class objects normally have __________ that perform useful operations on their data, but primitive variables do not. 1. fields 2. relationships 3. methods 4. instances
methods
Most of the programming languages used today are __________. 1. procedural 2. top-down 3. object-oriented 4. functional
object-oriented
When you work with a __________, you are using a storage location that holds a piece of data. 1. primitive variable 2. reference variable 3. numeric literal 4. binary number
primitive variable
Which of the following is a correct method header for receiving a two-dimensional array as an argument? 1. public static void passArray(int[1,2]) 2. public static void passArray(int [][]) 3. public static void passArray(int[1],[2]) 4. public static void passArray(int[], int[])
public static void passArray(int [][])
You can use the __________ method to replace an item at a specific location in an ArrayList 1. set 2. remove 3. replace 4. add
set
Instance methods do not have the __________ key word in their headers. 1. public 2. static 3. private 4. protected
static
Given that String[] str has been initialized, to get a copy of str[0] with all the characters converted to uppercase, you would use the __________ statement. 1. str.uppercase(); 2. str[0].upperCase(); 3. str.toUpperCase(); 4. str[0].toUpperCase();
str[0].toUpperCase();
A(n) __________ is used as an index to pinpoint a specific element within an array. 1. boolean value 2. element 3. argument 4. subscript
subscript
Which of the following is not involved in identifying the classes to be used when developing an object-oriented application? 1. a description of the problem domain 2. the code 3. a refined list of nouns that include only those relevant to the problem 4. all the nouns are identified
the code
The scope of a public instance field is __________. 1. only the class in which it is defined 2. inside the class but not inside any method 3. inside the parentheses of a method header 4. the instance methods and methods outside the class
the instance methods and methods outside the class
The scope of a private instance field is __________. 1. the instance methods of the same class 2. inside the class but not inside any method in that class 3. inside the parentheses of a method header 4. the method in which it is defined
the instance methods of the same class
__________ refers to combining data and code into a single object. 1. Data hiding 2. Abstraction 3. The constructor 4. Encapsulation
Encapsulation
Java allows you to create objects of the __________ class in the same way you would create primitive variables 1. Random 2. String 3. PrintWriter 4. Scanner
String
Which of the following statements will create a reference, str, to the String "Hello, World"? 1. String str = "Hello, World"; 2. string str = "Hello, World"; 3. String str = new "Hello, World"; 4. str = "Hello, World";
String str = "Hello, World";
Given the following two-dimensional array declaration, which statement is true? int[][] numbers = new int[6][9]; 1. The numbers array has 54 rows. 2. The numbers array has 15 rows. 3. The numbers array has 6 rows and 9 columns. 4. The numbers array has 6 columns and 9 rows.
The numbers array has 6 rows and 9 columns.
When an individual element of an array is passed to a method __________. 1. a reference to the array is passed 2. it is passed like any other variable 3. the method does not have access to the original array 4. All of these are true.
the method does not have access to the original array
A UML diagram does not contain __________. 1. the class name 2. the method names 3. the field names 4. the object names
the object names
When an object is passed as an argument to a method, what is passed into the method's parameter variable? 1. the class name 2. the object's memory address 3. the values for each field 4. the method names
the object's memory address
To indicate the data type of a variable in a UML diagram, you enter __________. 1. the variable name followed by the data type 2. the variable name followed by a colon and the data type 3. the class name followed by the variable name followed by the data type 4. the data type followed by the variable name
the variable name followed by a colon and the data type
Two or more methods in a class may have the same name as long as __________. 1. they have different return types 2. they have different parameter lists 3. they have different return types but the same parameter list 4. You cannot have two methods with the same name.
they have different parameter lists
What will be the results after the following code is executed? int[] array1 = new int[25]; ... // Code that will put values in array1 int value = array1[0]; for (int a = 1; a < array1.length; a++) { if (array1[a] < value) value = array1[a]; } 1. value contains the highest value in array1 2. value contains the lowest value in array1 3. value contains the sum of all the values in array1 4. value contains the average of all the values in array1
value contains the lowest value in array1
What does the following statement do? double[] array1 = new double[10]; 1. It declares array1 to be a reference to an array of double values. 2. It will allow valid subscripts in the range of 0 through 9. 3. It creates an instance of an array of ten double values. 4. It does all of these.
It does all of these.
For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; } 1. The y field is available to code written outside the Circle class. 2. The radius field is not available to code written outside the Circle class. 3. The radius, x, and y fields are members of the Circle class. 4. The x field is available to code that is written outside the Circle class.
The y field is available to code written outside the Circle class.
Given the following code, what will be the value of finalAmount when it is displayed? public class Order { private int orderNum; private double orderAmount; private double orderDiscount; public Order(int orderNumber, double orderAmt, double orderDisc) { orderNum = orderNumber; orderAmount = orderAmt; orderDiscount = orderDisc; } public int getOrderAmount() { return orderAmount; } public int getOrderDisc() { return orderDisc; } } public class CustomerOrder { public static void main(String[] args) { int ordNum = 1234; double ordAmount = 580.00; double discountPer = .1; Order order; double finalAmount = order.getOrderAmount() — order.getOrderAmount() * order.getOrderDisc(); System.out.printf("Final order amount = $%,.2f\n", finalAmount); } } 1. 528.00 2. 580.00 3. There is no value because the constructor has an error. 4. There is no value because the object, order, has not been created.
There is no value because the object, order, has not been created.
What would be the result after the following code is executed? final int SIZE = 25; int[] array1 = new int[SIZE]; ... // Code that will put values in array1 int value = 0; for (int a = 0; a <= array1.length; a++) { value += array1[a]; } 1. value contains the highest value in array1. 2. value contains the lowest value in array1. 3. value contains the sum of all the values in array1. 4. This code would cause the program to crash.
This code would cause the program to crash.
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; 1. a = 5 2. a = 8 3. a = 10 4. a = 13
a=5
The ___________ method is used to insert an item into an ArrayList. 1. insert 2. add 3. store 4. putItem
add
Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList? 1. set 2. store 3. add 4. insert
add
Java performs ____________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array. 1. active array sequencing 2. array bounds checking 3. scope resolution binding 4. buffer overrun protection
array bounds checking
The __________ indicates the number of elements the array can hold. 1. new operator 2. array's size declarator 3. array's data type 4. version of Java
array's size declarator
One or more objects may be created from a(n) __________. 1. field 2. method 3. instance 4. class
class
A(n) __________ can be thought of as a blueprint that can be used to create a type of __________. 1. object, class 2. class, object 3. cookie, cake 4. object, method
class, object
The binary search algorithm __________. 1. is less efficient than the sequential search algorithm 2. will cut the portion of the array being searched in half each time it fails to locate the search value 3. will have a maximum number of comparisons equal to the number of elements in the array 4. will, normally, have the number of comparisons that is half the number of elements in the array
will cut the portion of the array being searched in half each time it fails to locate the search value
A partially filled array is normally used __________. 1. when only a very small number of values need to be stored 2. when you know how many elements will be in the array but not what the values are 3. with an accompanying parallel array 4. with an accompanying integer value that holds the number of items stored in the array
with an accompanying integer value that holds the number of items stored in the array
What would be the result after the following code is executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; for(int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x[a]; } 1. x[] = {36, 78, 12, 24} and y[] = {23, 55, 83, 19} 2. x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24} 3. x[] = {23, 55, 83, 19} and y[] = {23, 55, 83, 19} 4. Nothing. This is a compile error.
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}