CSE 1273 Java Exam II Study Guide

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

A parameter variable's scope is: A) the method in which the parameter is declared B) the class to which the method belongs C) the main method D) All of the above

A

A search algorithm: a. is a way to locate a specific item in a larger collection of data b. is rarely used with arrays c. arranges elements in ascending order d. arranges elements in descending order

A

By default, Java initializes array elements with what value? a. 0 b. 100 c. 1 d. -1

A

If the this variable is used to call a constructor: A) a compiler error will result, if it is not the first statement of the constructor B) a compiler error will result, if it is the first statement of the constructor C) nothing will happen D) the this variable cannot be used as a constructor call

A

If you attempt to use a local variable before it has been given a value: A) a compiler error will occur B) the local variable will always contain the value 0 C) the results will be unpredictable D) the local variable will be ignored

A

In memory, an array of String objects a. consists of elements, each of which is a reference to a String object. b. is always implemented as a ragged array. c. consists of elements, each of which is a String object. d. must be initialized when the array is declared.

A

In the following code, Integer.parseInt(str), is an example of: int num; string str = "555"; num = Integer.parseInt(str) + 5; A) a value-returning method B) a void method C) a local variable D) a complex method

A

In the header, the method name is always followed by this: A) parentheses B) return type C) data type D) braces

A

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 ________. A) class name; attributes or fields; methods B) class name; object name; methods C) object name; attributes or fields; methods D) object name; methods; attributes or fields

A

Java automatically stores this value in all uninitialized static member variables: A) 0 B) -1 C) null D) false

A

Look at the following statement. import java.util.*; This is an example of: A) a wildcard import B) an explicit import C) unconditional import D) conditional import

A

Quite often you have to use this statement to make a group of classes available to a program. A) import B) use C) link D) assume

A

Subscript numbering always starts at what value? a. 0 b. 1 c. -1 d. None of the above

A

The following statement creates an ArrayList object. What is the purpose of the <String> notation? ArrayList<String> arr = new ArrayList<String>(); a. It specifies that only String objects may be stored in the ArrayList object. c. It specifies that String objects may not be stored in the ArrayList object. b. It specifies that the get method will return only String objects. d. It specifies that everything stored in the ArrayList object will be converted to a String.

A

The process of breaking a problem down into smaller pieces is sometimes called: A) divide and conquer B) scientific method C) top-down programming D) whole-into-part

A

The scope of a private instance field is: A) the instance methods of the same class B) inside the class, but not inside any method C) inside the parentheses of a method header D) the method in which they are defined

A

The term for the relationship created by object aggregation is: A) has a B) is a C) Sub-class object D) Inner class

A

The whole-part relationship created by object aggregation is more often called: A) a has a relationship B) an inner class relationship C) an extra class relationship D) an inside class relationship

A

This ArrayList class method deletes an item from an ArrayList. a. remove c. erase b. delete d. purge

A

This type of method performs a task and sends a value back to the code that called it. A) value-returning B) void C) complex D) local

A

Values stored in local variables: A) are lost between calls to the method in which they are declared B) retain their values from the last call to the method in which they are declared C) may be referenced by the calling method D) may be referenced by any other method, if the method in which they are declared is a public method

A

What do you call the number that is used as an index to pinpoint a specific element within an array? a. subscript b. global unique identifier c. element d. argument

A

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} }; a. 94 b. 84 c. 93 d. 95

A

What will be returned from the following method? public static double methodA() { double a = 8.5 + 9.5; return a; } A) 18.0 B) 18 (as an integer) C) 8 D) This is an error.

A

What will be the result of executing the following code? int[] x = {0, 1, 2, 3, 4, 5}; a. An array of 6 values ranging from 0 through 5 and referenced by the variable x will be created b. A compilation error will occur c. The program will crash when it is executed d. The value of x[1] will be 0, x[2] will be 0, x[3] will be 0, x[4] will be 0, x[5] will be 0, and x[6] will be 0.

A

What would be the results of the following code? 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 = 5 b. a = 8 c. a = 10 d. This is a compilation error, you cannot compare array elements

A

When an argument is passed to a method: A) its value is copied into the method's parameter variable B) its value may be changed within the called method C) values may not be passed to methods D) the method must not assign another value to the parameter that receives the argument

A

When an object is created, the attributes associated with the object are called: A) instance fields B) instance methods C) fixed attributes D) class instances

A

When an object, such as a String, is passed as an argument, it is: A) actually a reference to the object that is passed B) passed by value like any other parameter value C) encrypted D) necessary to know exactly how long the string is when writing the program

A

When the this variable is used to call a constructor: A) it must be the first statement in the constructor making the call B) it must be the last statement in the constructor making the call C) it can be anywhere in the constructor making the call D) you cannot use the this variable in a constructor call

A

When you are working with a ________, you are using a storage location that holds a piece of data. A) primitive variable B) reference variable C) numeric literal D) binary number

A

When you pass an argument to a method, be sure that the argument's data type is compatible with: A) the parameter variable's data type B) the method's return type C) the version of Java currently being used D) IEEE standards

A

Which of the following is NOT true about static methods? A) It is necessary for an instance of the class to be created to execute the method. B) They are created by placing the key word static after the access specifier in the method header. C) They are called directly from the class. D) They are often used to create utility classes that perform operations on data, but have no need to collect and store data.

A

Which of the following statements will create a reference, str, to the String, "Hello, World"? A) String str = "Hello, World"; B) string str = "Hello, World"; C) String str = new "Hello, World"; D) str = "Hello, World";

A

You cannot use the == operator to compare the contents of: A) objects B) strings C) integers D) Boolean values

A

You should always document a method by writing comments that appear: A) just before the method's definition B) just after the method's definition C) at the end of the file D) only if the method is more than five lines long

A

You should not define a class field that is dependent upon the values of other class fields: A) in order to avoid having stale data B) because it is redundant C) because it should be defined in another class D) in order to keep it current

A

You use this method to determine the number of items stored in an ArrayList object. a. numberItems c. size b. capacity d. items

A

) In the following code, System.out.println(num) is an example of: double num = 5.4; System.out.println(num); num = 0.0; A) a value-returning method B) a void method C) a complex method D) a local variable

B

A deep copy of an object: A) is an assignment of that object to another object B) is an operation that copies an aggregate object, and all the objects it references C) is a bogus term, it has no meaning D) is always a private method

B

A special variable that holds a value being passed into a method is called what? A) Modifier B) Parameter C) Alias D) Argument

B

A static field is created by placing: A) the key word static after the field name B) the key word static after the access specifier and before the field's data type C) the key word static after the access specifier and field's data type D) it in a static field block

B

All @param tags in a method's documentation comment must: A) end with a */ B) appear after the general description of the method C) appear before the method header D) span several lines

B

Another term for an object of a class is: A) access specifier B) instance C) member D) method

B

Assume that the following method header is for a method in class A. public void displayValue(int value) Assume that the following code segments appear in another method, also in class A. Which contains a legal call to the displayValue method? A) int x = 7; void displayValue(x); B) int x = 7; displayValue(x); C) int x = 7; displayValue(int x); D) int x = 7; displayValue(x)

B

CRC stands for: A) Code, Reuse, Constancy B) Class, Responsibilities, Collaborations C) Class, Redundancy, Collections D) Class, Recyclability, Collaborations

B

Given the following two-dimensional array declaration, which statement is true? int [][] numbers = new int [6] [9]; a. The array numbers has 6 columns and 9 rows b. The array numbers has 6 rows and 9 columns c. The array numbers has 15 rows d. The array numbers has 54 rows

B

If object1 and object2 are objects of the same class, to make object2 a copy of object1: A) assign object1 to object2, such as object2 = object1; B) write a copy method that will make a field by field copy of object1 data members into object2 data members C) use the Java copy method that is a part of the Java language D) use the default constructor to create object2 with object1 data members

B

If the following is from the method section of a UML diagram, which of the following statements is TRUE? + equals(object2:Stock) : boolean A) This is a private method that receives two objects from the Stock class and returns a boolean value. B) This is a public method that accepts a Stock object as its argument and returns a boolean value. C) This is a private method that returns a boolean value. D) This is a public method that returns a Stock object.

B

If you have defined a class SavingsAccount with a public static method getNumberOfAccounts(), and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts()method? A) getNumberOfAccounts(); B) SavingsAccount.getNumberOfAccounts(); C) getNumberOfAccounts(account20); D) None of the above, you cannot call a static method.

B

In Java, you do not use the new operator when you use a(n): a. array size declarator b. initialization list c. two-dimensional array d. All of the above

B

In a @return tag statement the description: A) cannot be longer than one line B) describes the return value C) must be longer than one line D) describes the parameter values

B

In a UML diagram to indicate the data type of a variable enter: A) the variable name followed by the data type B) the variable name followed by a colon and the data type C) the class name followed by the variable name followed by the data type D) the data type followed by the variable name

B

In order to do a binary search on an array, a. the values of the array must be numeric b. the array must first be sorted in ascending order c. you must first do a sequential search of the array to assure the element you are looking for is there d. There are no requirements

B

In the cookie cutter metaphor, think of the ________ as a cookie cutter and ________ as the cookies. A) object; classes B) class; objects C) class; fields D) attribute; methods

B

Instance methods do not have this key word in their headers: A) public B) static C) private D) protected

B

It is common practice in object-oriented programming to make all of a class's: A) methods private B) fields private C) fields public D) fields and methods public

B

Java allows you to create objects of this class in the same way you would create primitive variables. A) Random B) String C) PrintWriter D) Scanner

B

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. a. active array sequencing b. array bounds checking c. scope resolution binding d. buffer overrun protection

B

Look at the following declaration: enum Tree { OAK, MAPLE, PINE } What is the ordinal value of the MAPLE enum constant? A) 0 B) 1 C) 2 D) 3 E) Tree.MAPLE

B

Look at the following statement. import java.util.Scanner; This is an example of A) a wildcard import B) an explicit import C) unconditional import D) conditional import

B

Methods are commonly used to: A) speed up the compilation of a program B) break a problem down into small manageable pieces C) emphasize certain parts of the logic D) document the program

B

Methods that operate on an object's fields are called: A) instance variables B) instance methods C) public methods D) private methods

B

One or more objects may be created from a(n): A) field B) class C) method D) instance

B

Static methods can only operate on ________ fields. A) instance B) static C) global D) local

B

The JVM periodically performs this process to remove unreferenced objects from memory. A) memory sweeping B) garbage collection C) memory shuffling D) system restore

B

The binary search algorithm: a. is less efficient than the sequential search algorithm b. will cut the portion of the array being searched in half each time the loop fails to locate the search value c. will have a maximum number of comparisons equal to the number of elements in the array d. will have an average of N/2 comparisons, where N is the number of elements in the array

B

This ArrayList class method is used to insert an item into an ArrayList. a. insert c. store b. add d. putItem

B

This indicates the number of elements, or values, the array can hold. a. the new operator b. the array's size declarator c. the array's data type d. the version of Java

B

This is a group of related classes. A) archive B) package C) collection D) attachment

B

This type of method performs a task and then terminates. A) value-returning B) void C) local D) simple

B

To return an array of long values from a method, use this as the return type for the method. a. long b. long[] c. long[ARRAY_SIZE] d. []long

B

Two or more methods in a class may have the same name as long as: A) they have different return types B) they have different parameter lists C) they have different return types, but the same parameter list D) you cannot have two methods with the same name

B

Values that are sent into a method are called: A) variables B) arguments C) literals D) types

B

What do you normally use with a partially-filled array? a. A class that does nothing but manage the array b. An accompanying parallel array c. An accompanying integer value that holds the number of items stored in the array d. An accumulator

B

What is stored by a reference variable? A) A binary encoded decimal B) A memory address C) An object D) A string

B

What will be returned from a method, if the following is the method header? public Rectangle getRectangle() A) An object of the class Rectangle B) The address of an object of the class Rectangle C) The values stored in the data members of the Rectangle object the method changed D) A graph of a rectangle

B

What will be returned from the following method? public static float[] getValue(int x) a. A float value b. An array of float values c. An integer d. An array of integers

B

What will be the value of x[1] after the following code is executed? int[] x = {22, 33, 44}; arrayProcess(x[1]); ... public static void arrayProcess(int a) { a = a + 5; } a. 27 b. 33 c. 38 d. 49

B

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; } a. 170 b. 180 c. 190 d. 200

B

What would be the results after the following code was 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]; } a. x[] = {36, 78, 12, 24} and y[] = {23, 55, 83, 19} b. x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24} c. x[] = {23, 55, 83, 19} and y[] = {23, 55, 83, 19} d. This is a compilation error

B

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; a. x[] = {36, 78, 12, 24} and y[] = {23, 55, 83, 19} b. x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24} c. x[] = {23, 55, 83, 19} and y[] = {23, 55, 83, 19} d. This is a compilation error

B

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]; } a. value contains the highest value in array1 b. value contains the lowest value in array1 c. value contains the sum of all the values in array1 d. value contains the average of the values in array1

B

When a field is declared static, there will be: A) a copy of the field in each class object B) only one copy of the field in memory C) a copy of the field for each static method in the class D) only two copies of the field in memory

B

When a method tests an argument and returns a true or false value, it should return: A) a zero for true and a one for false B) a boolean value C) a zero for false and a non-zero for true D) a method should not be used for this type test

B

When a method's return type is a class, what is actually returned to the calling program? A) An object of that class B) A reference to an object of that class C) Only the values in the object that the method accessed D) Nothing, the return type is strictly for documentation in this situation.

B

When a reference variable is passed as an argument to a method: A) a copy of the variable's value is passed into the method's parameter B) the method has access to the object that the variable references C) the method becomes a static method D) the program will terminate

B

When an argument value is passed to a method, the receiving parameter variable is: A) declared within the body of the method B) declared in the method header inside the parentheses C) declared in the calling method D) uses the declaration of the argument

B

When an object is passed as an argument to a method, what is passed into the method's parameter variable? A) the class name B) the object's memory address C) the values for each field D) the method names

B

Which of the following is NOT part of a method call? A) method name B) return type C) parentheses D) all of the above are part of a method call

B

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

B

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

B

You can use this ArrayList class method to insert an item at a specific location in an ArrayList. a. insert c. store b. add d. putItem

B

A class specifies the ________ and ________ that a particular type of object has. A) relationships; methods B) fields; object names C) fields; methods D) relationships; object names

C

A class's responsibilities include: A) the things a class is responsible for doing B) the things a class is responsible for knowing C) both A and B D) neither A nor B

C

A constructor: A) always accepts two arguments B) has return type of void C) has the same name as the class D) always has an access specifier of private

C

A declaration for an enumerated type begins with this key word. A) enumerated B) enum_type C) enum D) ENUM

C

A ragged array is: a. a two-dimensional array for which the number of rows is unknown b. a one-dimensional array for which the number of elements is unknown c. a two-dimensional array where the rows are of different lengths d. There is no such thing as a ragged array

C

After the header, the body of the method appears inside a set of: A) brackets, [] B) parentheses, () C) braces, {} D) double quotes, ""

C

Any method that calls a method with a throws clause in its header must: A) handle the potential exception B) have the same throws clause C) both of the above D) do nothing, the called program will take care of the throws clause

C

Assume the class BankAccount has been created, and the following statement correctly creates an instance of the class: BankAccount account = new BankAccount(5000.0); What is TRUE about the following statement? System.out.println(account); A) The method will display unreadable binary data on the screen. B) A compiler error will occur. C) The account object's toString method will be implicitly called. D) A runtime error will occur.

C

Class objects normally have ________ that perform useful operations on their data, but primitive variables do not. A) fields B) instances C) methods D) relationships

C

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

C

Enumerated types have this method, which returns the position of an enum constant in the declaration list. A) toString B) position C) ordinal D) location

C

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

C

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); } } A) 528.00 B) 580.00 C) 522.00 D) There is no value because the object order has not been created.

C

Given the following method header, which of the method calls would be an error? public void displayValues(double x, int y) A) displayValue(a,b); // where a is a long and b is a byte B) displayValue(a,b); // where a is an int and b is a byte C) displayValue(a,b); // where a is a short and b is a long D) They would all give an error.

C

Given the following method header, which of the method calls would be an error? public void displayValues(int x, int y) A) displayValue(a,b); // where a is a short and b is a byte B) displayValue(a,b); // where a is an int and b is a byte C) displayValue(a,b); // where a is a short and b is a long D) They would all give an error.

C

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[]? a. 1 through 15 b. 1 through 14 c. 0 through 14 d. 0 through 15

C

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens? A) Control is returned to method A. B) Control is returned to method B. C) Control is returned to method C. D) The program terminates.

C

If the following is from the method section of a UML diagram, which of the following statements is TRUE? + add(object2:Stock): Stock A) This is a private method named add that accepts and returns objects of the Stock class. B) This is a private method named Stock that adds two objects. C) This is a public method named add that accepts and returns references to objects in the Stock class. D) This is a public method named Stock that adds two objects.

C

If you attempt to perform an operation with a null reference variable: A) the resulting operation will always be zero B) the results will be unpredictable C) the program will terminate D) Java will create an object to reference the variable

C

If you have defined a class named SavingsAccount with a public static data member named numberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts? A) numAccounts = account20.numAccounts; B) numAccounts = numberOfAccounts; C) numAccounts = SavingsAccount.numberOfAccounts; D) None of the above, you cannot reference a static data member.

C

In UML diagrams, this symbol indicates that a member is private: A) * B) # C) - D) +

C

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

C

Look at the following declaration: enum Tree { OAK, MAPLE, PINE } What is the fully-qualified name of the PINE enum constant? A) PINE B) enum.PINE C) Tree.PINE D) Tree(PINE) E) PINE.Tree

C

Most programming languages that are in use today are: A) procedural B) logic C) object-oriented D) functional

C

Overloading means multiple methods in the same class: A) have the same name, but different return types B) have different names, but the same parameter list C) have the same name, but different parameter lists D) perform the same function

C

The header of a value-returning method must specify this. A) The method's local variable names B) The name of the variable in the calling program that will receive the returned value C) The data type of the return value D) All of the above

C

The phrase divide and conquer is sometimes used to describe: A) the backbone of the scientific method B) the process of dividing functions C) the process of breaking a problem down into smaller pieces D) the process of using division to solve a mathematical problem

C

The sequential search algorithm: a. requires the array to be ordered b. must always be implemented as a method c. uses a loop to sequentially step through an array, starting with the first element d. will not execute, if the element is not in the array

C

This part of a method is a collection of statements that are performed when the method is executed. A) method header B) return type C) method body D) method modifier

C

To compare two objects in a class: A) use the == operator, e.g. object1 == object2 B) write a method to do a byte-by-byte compare of the two objects C) write an equals method that will make a field by field compare of the two objects D) Since objects consist of several fields, you cannot compare them

C

To document the return value of a method, use this in a documentation comment. A) The @param tag B) The @comment tag C) The @return tag D) The @returnValue tag

C

What is wrong with the following method call? displayValue (double x); A) There is nothing wrong with the statement. B) displayValue will not accept a parameter. C) Do not include the data type in the method call. D) x should be a String.

C

What will be the result of the following code? int num; string str = "555"; num = Integer.parseInt(string str) + 5; A) num will be set to 560. B) str will have a value of "560". C) The last line of code will cause an error. D) Neither num or str will be changed.

C

What will be the results of the following code? final int ARRAY_SIZE = 5; double[] x = new double[ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; } a. All the values in the array are initialized to 10.0 b. All the values, except the first, are set to 10.0 c. An error will occur when the program runs. d. There will be a compilation error

C

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; } } a. 27 b. 33 c. 38 d. 49

C

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; } a. 50 b. 55 c. 60 d. 65

C

What would be the results of the following code? 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]; } a. value contains the highest value in array1 b. value contains the lowest value in array1 c. value contains the sum of all the values in array1 d. This would cause the program to crash

C

When an individual element of an array is passed to a method: a. a reference to the array is passed b. it is passed like any other variable c. the method does not have direct access to the original array d. All of the above

C

When writing the documentation comments for a method, you can provide a description of each parameter by using a: A) @comment tag B) @doc tag C) @param tag D) @return tag

C

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

C

Which of the following is NOT involved in finding the classes when developing an object-oriented application? A) Describe the problem domain. B) Identify all the nouns. C) Write the code. D) Refine the list of nouns to include only those that are relevant to the problem.

C

Which of the following is NOT true about static methods? A) It is not necessary for an instance of the class to be created to execute the method. B) They are created by placing the key word static after the access specifier in the method header. C) They are called from an instance of the class. D) They are often used to create utility classes that perform operations on data, but have no need to collect and store data.

C

Which of the following is a valid declaration for a ragged array? a. int[] ragged = new int[5]; b. int[][] ragged = new int[5][6]; c. int[][] ragged = new int[5][]; d. int[][] ragged = new int[][5];

C

Which of the following is included in a method call? A) return type B) method modifiers C) parentheses D) return variable

C

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"; A) 1 B) 2 C) 1 and 2 D) neither 1 or 2

C

Which of the following would be a valid method call for the following method? public static void showProduct (int num1, double num2) { int product; product = num1 * (int)num2; System.out.println("The product is " + product); } A) showProduct(5.5, 4.0); B) showProduct(10.0, 4); C) showProduct(10, 4.5); D) showProduct(33.0, 55.0);

C

You cannot use the fully-qualified name of an enum constant for this. A) a switch expression B) an argument to a method C) a case expression D) all of these

C

A UML diagram does not contain: A) the class name B) the method names C) the field names D) object names

D

A constructor is a method that: A) returns an object of the class. B) never receives any arguments. C) with the name ClassName.constructor. D) performs initialization or setup operations.

D

A value-returning method must specify this as its return type in the method header. A) an int B) a double C) a boolean D) any valid data type

D

An object's ________ is simply the data that is stored in the object's fields at any given moment. A) value B) assessment C) record D) state

D

Assuming the following declaration exists: enum Tree { OAK, MAPLE, PINE } What will the following code display? System.out.println(Tree.OAK); A) Tree.OAK B) 0 C) 1 D) OAK E) Nothing. This statement will cause an error.

D

Breaking a program down into small manageable methods: A) makes problems more easily solved B) allows for code reuse C) simplifies programs D) all of the above

D

Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by: A) using the public access specifier on the class methods B) using the private access specifier on the class methods C) using the private access specifier on the class definition D) using the private access specifier on the class fields

D

For the following code, which statement is NOT true? public class Circle { private double radius; public double x; private double y; } A) x is available to code that is written outside the Circle class. B) radius is not available to code written outside the Circle class. C) radius, x, and y are called members of the Circle class. D) y is available to code that is written outside the Circle class.

D

For the following code, which statement is NOT true? public class Sphere { private double radius; public double x; private double y; private double z; } A) x is available to code that is written outside the Circle class. B) radius is not available to code written outside the Circle class. C) radius, x, y, and z are called members of the Circle class. D) z is available to code that is written outside the Circle class.

D

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: a. str.uppercase(); b. str[0].upperCase(); c. str.toUpperCase(); d. str[0].toUpperCase();

D

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); } } A) 528.00 B) 580.00 C) There is no value because the constructor has an error. D) There is no value because the object order has not been created.

D

If numbers is a two-dimensional array, which of the following would give the length of row r? a. numbers.length b. numbers.length[r] c. numbers[r].length[r] d. numbers[r].length

D

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? a. for (int row = 1; row < numbers.length; row++) { for (int col = 1; col < numbers.length; col++) total += numbers[row][col]; } b. for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers.length; col++) total += numbers[row][col]; } c. for (int row = 0; row < numbers[row].length; row++) { for (int col = 0; col < numbers.length; col++) total += numbers[row][col]; } d. for (int row = 0; row < numbers.length; row++) { for (int col = 0; col < numbers[row].length; col++) total += numbers[row][col]; }

D

In UML diagrams, this symbol indicates that a member is public. A) / B) @ C) - D) +

D

In a general sense, a method is: A) a plan B) a statement inside a loop C) a comment D) a collection of statements that performs a specific task

D

Local variables can be initialized with: A) constants B) parameter values C) the results of an arithmetic operation D) any of the above

D

Local variables: A) are hidden from other methods B) may have the same name as local variables in other methods C) lose the values stored in them between calls to the method in which the variable is declared D) All of the above

D

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

D

The following package is automatically imported into all Java programs. A) java.java B) java.default C) java.util D) java.lang

D

The lifetime of a method's local variable is: A) the duration of the program B) the duration of the class to which the method belongs C) the duration of the method that called the local variable's method D) only while the method is executing

D

The only limitation that static methods have is: A) they can refer to only non-static members of the class B) they can only be called from static members of the class C) they must be declared as public methods D) they cannot refer to non-static members of the class

D

The scope of a public instance field is: A) only the class in which it is defined B) inside the class, but not inside any method C) inside the parentheses of a method header D) the instance methods and methods outside the class

D

This refers to the combining of data and code into a single object. A) Data hiding B) Abstraction C) Object D) Encapsulation

D

To create a method you must write its: A) header B) return type C) body D) definition

D

What does the following UML diagram entry mean? + setHeight(h : double) : void A) this is a public attribute named Height and is a double data type B) this is a private method with no parameters and returns a double data type C) this is a private attribute named Height and is a double data type D) this is a public method with a parameter of data type double and does not return a value

D

What does the following statement do? double[] array1 = new double[10]; a. Declares array1 to be a reference to an array of double values b. Creates an instance of an array of 10 double values c. Will allow valid subscripts in the range of 0 - 9 d. All of the above

D

What will be returned from the following method? public static int methodA() { double a = 8.5 + 9.5; return a; } A) 18.0 B) 18 (as an integer) C) 8.0 D) This is an error.

D

What would be the results of the following code? 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]; } a. value contains the highest value in array1 b. value contains the lowest value in array1 c. value contains the sum of all the values in array1 d. This would cause the program to crash

D

When an array is passed to a method: a. a reference to the array is passed b. it is passed just as an object c. the method has direct access to the original array d. All of the above

D

Which of the following are classes from the Java API? A) Scanner B) Random C) PrintWriter D) All of the above

D

Which of the following is NOT a benefit derived from using methods in programming? A) Pproblems are more easily solved. B) simplifies programs C) code reuse D) All of the above are benefits

D

Which of the following is NOT a part of the method header? A) return type B) method name C) parentheses D) semicolon

D

Which of the following would be a valid method call for the following method? public static void showProduct(double num1, int num2) { double product; product = num1 * num2; System.out.println("The product is " + product); } A) showProduct("5", "40"); B) showProduct(10.0, 4.6); C) showProduct(10, 4.5); D) showProduct(3.3, 55);

D

Which of the statements are true about the following code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE]; a. Declares array1 to be a reference to an array of long values b. Creates an instance of an array of 10 long values c. Will allow valid subscripts in the range of 0 - 9 d. All of the above

D

You can use this ArrayList class method to replace an item at a specific location in an ArrayList. a. replace c. store b. add d. set

D

In Java, it is possible to write a method that will return: A) a whole number B) a monetary value C) a string of characters D) a reference to an object E) All of the above

E

Which of the following values can be passed to a method that has an int parameter variable? A) float B) double C) long D) All of the above E) None of the above

E

A method that gets a value from a class's field but does not change it is known as a mutator method.

False

A sorting algorithm is used to locate a specific item in a larger collection of data.

False

An array can hold multiple values of several different data types simultaneously.

False

If a class has a method named finalize, it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector.

False

If a[] and b[] are two integer arrays, the expression a == b compares the array contents.

False

In the method header the static method modifier means the method is available to code outside the class.

False

In the method header, the method modifier public means that the method belongs to the class, not a specific object.

False

Instance methods should be declared static.

False

Java limits the number of dimensions that an array may have to 15.

False

Only constants and variables may be passed as arguments to methods.

False

The names of the enum constants in an enumerated data type must be enclosed in quotation marks.

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

The this key word is the name of a reference variable that is available to all static methods.

False

When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.

False

You can declare an enumerated data type inside of a method.

False

A class in not an object, but a description of an object.

True

A class's static methods do not operate on the fields that belong to any instance of the class.

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 parameter variable's scope is the method in which the parameter is declared.

True

A single copy of a class's static field is shared by all instances of the class.

True

A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.

True

A value-returning method can return a reference to a non-primitive type.

True

An ArrayList object automatically expands in size to accommodate the items stored in it.

True

An access specifier indicates how the class may be accessed.

True

An enumerated data type is actually a special type of class.

True

An instance of a class does not have to exist in order for values to be stored in a class's static fields.

True

An object can store data.

True

Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.

True

Any method that calls a method with a throws clause in its header must either handle the potential exception or have the same throws clause.

True

Both instance fields and instance methods are associated with a specific instance of a class, and they cannot be used until an instance of the class is created.

True

Constants, variables, and the values of expressions may be passed as arguments to a method.

True

Declaring an array reference variable does not create an array.

True

Enum constants have a toString method.

True

If a class has a method named finalize, it is called automatically just before an instance of the class is destroyed by the garbage collector.

True

If you write a toString method for a class, Java will automatically call the method any time you concatenate an object of the class with a string.

True

If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent: System.out.println(object1); System.out.println(object1.toString());

True

Instance methods do not have the key word static in their headers.

True

Java does not limit the number of dimensions that an array may have.

True

Methods are commonly used to break a problem into small manageable pieces.

True

No statement outside the method in which a parameter variable is declared can access the parameter by its name.

True

Objects in an array are accessed with subscripts, just like any other data type in an array.

True

Once an array is created, its size cannot be changed.

True

Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.

True

The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.

True

The expression in a return statement can be any expression that has a value.

True

The java.lang package is automatically imported into all Java programs.

True

The key word this is the name of a reference variable that an object can use to refer to itself.

True

The term "no-arg constructor" is applied to any constructor that does not accept arguments.

True

To compare the contents of two arrays, you must compare the elements of the two arrays.

True

Two general categories of methods are void methods and value returning methods.

True

When an array of objects is declared, but not initialized, the array values are set to null.

True

When an object is passed as an argument, it is actually a reference to the object that is passed.

True

When an object reference is passed to a method, the method may change the values in the object.

True

You must have a return statement in a value-returning method.

True


Ensembles d'études connexes

PREPU - UNFINISHED Chapter 23: Antipsychotic Drugs

View Set

First Aid Handbook: Part 2 Medical Emergencies

View Set

Chapter 6 Section 2; Cultural geography of Canada

View Set

Lewis Ch. 23 - Integumentary Problems, Lewis - Med-Surg Nursing - Study Guide - Ch. 11, alterations in skin integrity Questions

View Set

Cooper Ch 11: Positive Reinforcement

View Set

MCB 305 EX 3 quiz, clicker, and preceptor review

View Set