CISY JAVA Ch 12, 13
In UML diagrams, this symbol indicates that a member is public.
+
In UML diagrams, this symbol indicates that a member is private:
-
This ArrayList class method is used to insert an item into an ArrayList.
.add
By default, Java initializes array elements with what value?
0
Subscript numbering always starts at what value?
0
If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?
0 to 14
Which of the following statements will create a reference, str, to the string, "Hello, world"? (1) String str = new String("Hello, world"); (2) String str = "Hello, world";
1 and 2
What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; }
180
What will be the value of x[1] after the following code is executed? int[] x = {22, 33, 44}; arrayProcess(x); ... public static void arrayProcess(int[] a) { for(int k = 0; k < 3; k++) { a[k] = a[k] + 5; } }
38
Given the following two-dimensional array declaration, which statement is TRUE? int [][] numbers = new int [6] [9];
6 rows 9 columns
What will be the value of x[8] after the following code has been 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; }
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} };
94
For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"};
A reference to the String "ghi
What do you normally use with a partially-filled array?
An accompanying integer value that holds the number of items stored in the array
Methods that operate on an object's fields are called:
Instance methods
A constructor is a method that:
Performs initialization or setup operations.
Java allows you to create objects of this class in the same way you would create primitive variables.
String
Which of the following statements will create a reference, str, to the String, "Hello, World"?
String str = "Hello, World";
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); } }
There is no value because the object order has not been created
What would be the results of the following code? 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]; }
Value contains the lowest value in array1.
What is stored by a reference variable?
a memory address
A ragged array is:
a two-dimensional array where the rows are of different lengths
Which of the following are classes from the Java API?
all of the above
Which of the statements are TRUE about the following code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE];
all of the above
What will be the results of the following code? final int ARRAY_SIZE = 5; float[] x = float[ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; }
an error will occur
What will be returned from the following method? public static float[] getValue(int x)
array of float
This indicates the number of elements, or values, the array can hold.
array's size declarator
In your textbook the general layout of a UML diagram is a box that is divided into three sections. The top section has the ________; the middle section holds ________; the bottom section holds ________.
class name; attributes or fields; methods
In memory, an array of String objects:
consists of elements, each of which is a reference to a String object
This refers to the combining of data and code into a single object.
encapsulation
Look at the following statement. import java.util.Scanner; This is an example of
explicit import
An access specifier indicates how the class may be accessed.
false
An array can hold multiple values of several different data types simultaneously.
false
Java limits the number of dimensions that an array may have to 15.
false
The public access specifier for a field indicates that the attribute may not be accessed by statements outside the class.
false
The term "default constructor" is applied to the first constructor written by the author of a class.
false
A class specifies the ________ and ________ that a particular type of object has.
fields; methods
It is common practice to use a ________ variable as a size declarator.
final
Which of the following for loops is valid, given the following declaration? String[] names = {"abc", "def", "ghi", "jkl"};
for (int i = 0; i < names.length; i++) System.out.println(names[i].length());
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?
for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }
A constructor:
has the same name as the class
Overloading means multiple methods in the same class:
have the same name, but different parameter lists
You should not define a class field that is dependent upon the values of other class fields:
in order to avoid having stale data
When an object is created, the attributes associated with the object are called:
instance fields
A search algorithm:
is a way to locate a specific item in a larger collection of data
The following package is automatically imported into all Java programs.
java.lang
To return an array of long values from a method, use this as the return type for the method.
long[]
Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.
methods
You use this method to determine the number of items stored in an ArrayList object.
numberItems
Most programming languages that are in use today are:
object oriented
This is a group of related classes.
package
When you are working with a ________, you are using a storage location that holds a piece of data.
primitive variable
Which of the following is a correct method header for receiving a two-dimensional array as an argument?
public static void passArray(int [][])
Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement:
str[0].toUpperCase();
The scope of a private instance field is:
the instance methods of the same class
When an individual element of an array is passed to a method:
the method does not have direct access to the original array
When an object is passed as an argument to a method, what is passed into the method's parameter variable?
the object's memory address
Two or more methods in a class may have the same name as long as:
they have different parameter lists
What does the following UML diagram entry mean? + setHeight(h : double) : void
this is a public method with a parameter of data type double and does not return a value
A class in not an object, but a description of an object.
true
A constructor is a method that is automatically called when an object is created.
true
A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator method.
true
A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.
true
Objects in an array are accessed with subscripts, just like any other data type in an array
true
The java.lang package is automatically imported into all Java programs.
true
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
true
When an array of objects is declared, but not initialized, the array values are set to null.
true
The binary search algorithm:
will cut the portion of the array being searched in half each time the loop fails to locate the search value
Which of the following is NOT involved in finding the classes when developing an object-oriented application?
write the code
What would be the results after the following code was executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; x = y; y = x;
x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}
For the following code, which statement is NOT true? public class Circle { private double radius; public double x; private double y; }
y is available to code that is written outside the Circle class.