CPSC

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Merge sort has a O(n log2(n)) complexity. If a computer can sort 1,024 elements in an amount of time x, approximately how long will it take the computer to sort 1,024 times that many, or 1,048,576 elements?

2,048x

How large does n need to be so 0.3n2 is greater than 2.5n - 3?

7

Which annotation is used to mark test methods when using JUnit?

@Test

Which of the following statements about sets is correct?

A collection of unique elements organized for efficiency.

Suppose we create a deque (double-ended queue) data structure. It is basically a queue, with its addLast and removeFirst operations, but we also add the addFirst and removeLast operations. Which of the following is best modeled by the deque data structure?

A computer keyboard typing buffer.

Which return value of the JFileChooser object's showOpenDialog method indicates that a file was chosen by the user at run time?

APPROVE_OPTION

A class named CurrencyTranslator would most probably fall into which of the following class categories?

Actor classes

Which of the following statements is true regarding method parameters in Java?

All method parameters use the call-by-value mechanism.

In Java, which of the following mechanisms describe the copying of an object reference into a parameter variable?

Call-by-value.

During the implementation phase, which of the following statements is true?

Class instance variables can be determined from the UML diagrams.

A theater needs a TicketCounter to keep track of the number of tickets sold. There are two types of ticket: regular and discount. Which technique would be the best approach to printing the number of tickets sold?

Create a toString() method in the class that creates a representation with the number of discount and regular priced tickets sold.

In designing an inheritance hierarchy it is helpful first to list classes that are part of the hierarchy and then organize those classes via an inheritance diagram. Once this has been done, what is the next step in the design?

Determine common responsibilities among the classes

Which of the following statements about abstract methods is true?

Has a name, parameters, and a return type, but no code in the body of the method.

A new class is proposed to collect information about a group of DVDs. Which of the following is the best structure for this class?

Have separate classes for a single DVD and the entire DVD collection.

Which of the following classes implement the Comparable interface? I Date II Collections III String

I and III only

When does quicksort's worst-case run-time behavior occur? I when the data is randomly initialized in the array II when the data is in ascending order III when the data is in descending order

II and III only

When a Java program terminates and reports an exception, the error message contains which pieces of useful information? I. the compile and revision control history of the source code changes that caused the error II. the name of the exception that occurred III. the stack trace

II, III only

Which statements about the enhanced for loop are true for arrays of primitive data? I. It is suitable for all array algorithms. II. It does not allow the contents of the array to be modified. III. It does not require the use of an index variable.

II, III only

Under which of the following conditions must you qualify the name of a public class member?

If it is to be used outside its class.

In the hierarchy of Exception classes, the NumberFormatException class is a subclass of the ____ class.

IllegalArgumentException

The String class is an example of which of the following types of classes?

Immutable class

Which of the following is a true statement regarding consistency in coding?

Inconsistencies are an annoyance, because they can be so easily avoided

You have determined a need for an Employee class and a TemporaryEmployee class in your program. Which relationship is most appropriate between these classes?

Inheritance

Which of the following types of methods are invoked on objects

Instance method

Assume that the Measurable interface is defined with a static sum method that computes the sum of the Measurable objects passed in as an array, and that BankAccount implements the Measurable interface. Also assume that there is a variable branchAccounts that is an object reference to a populated array of BankAccount objects for a bank branch. Which of the following represents a correct invocation of the sum method to find the total balance of all accounts at the branch?

Measurable.sum(branchAccounts)

Listeners are typically implemented as inner classes. Which of the following statements is NOT true about inner class access to variables from the surrounding class?

Methods of an inner class cannot access variables from the surrounding class.

Mutator methods exhibit which of the following types of side effect?

Modification of private instance variables.

A new method, getMonthName, to get the name of the Date's month ("January", February", etc.) is to be added to the class Date. How will the instance variables need to be changed to handle this new method?

No change is needed

Can the method lastDayOfMonth be changed to be a static method by just changing the header to the following? private static int lastDayOfMonth()

No. It could no longer access the month instance variable

Can you search the following array using binary search? int[] A = {6, 5, 4, 2, 0, 1, -1, -17};

No. It must be sorted

In the worst case, quicksort is a(n) ____ algorithm.

O(n2)

When are statements in a class-level static initialization block executed?

Once when the class is loaded.

A static method can have which of the following types of parameters?

Only parameter variables.

Given the following method header, other would be classified as which of the following parameter types? public void transfer(double amount, BankAccount other)

Parameter variable.

Why can't Java methods change parameters of primitive type?

Parameters of primitive type are considered by Java methods to be local variables.

Which of the following does NOT describe a particular side effect related to standard output?

Programmers may be surprised by unexpected method actions

Which of the following statements regarding static methods is true

Static methods are not very common.

Which of the following is an example of an immutable class?

String

When declared as protected, which statement is true about the access to data in an object?

The data is accessible only by that class's methods, by all of its subclasses, and by methods in classes within the same package.

What will have to change if the instance variables month and day of the Date class are replaced by the single instance integer variable dayOfTheYear?

The implementation of the methods will change, but the interface will not need to change

Which of the following is a good indicator that a class is overreaching and trying to accomplish too much?

The public interface refers to multiple concepts

Which of the following statements about comparing objects is correct?

The purpose of the equals method is to compare whether two objects have the same contents.

Assume we are using quicksort to sort an array in ascending order. What can we conclude about the indexes of two pivot elements placed in consecutive recursive calls?

They are randomly located

Which of the following constitutes a common reason for creating a static method?

To encapsulate a computation that involves only numbers.

You wish to implement a callback method for an object created from a library class that you cannot change. What is the preferred way to accomplish this?

Use a helper class that implements the callback method.

Which class category has static methods and constants, but no objects?

Utility class

In which of the following cases could a static variable be declared as something other than private?

When implementing static constants

____ relationships come from the collaboration columns on the CRC cards.

dependency

A class should represent multiple concept from a problem domain.

false

To create a TreeSet for a class of objects, the object class must ____.

implement the Comparable interface

Which statement will import the static methods of the Math class into a program so they do not need the Math. prefix before them in the code?

import static java.lang.Math.*;

Which sort algorithm starts with an initial sequence of size 1, which is assumed to be sorted, and increases the size of the sorted sequence in the array in each iteration?

insertion sort

Which of the following are not allowed in a Java 8 interface declaration?

instance variables

The dependency relationship is sometimes referred to as the ____ relationship.

knows-about

A collection that allows speedy insertion and removal of already-located elements in the middle of it is called a ____.

linked list

If an element is present in an array of length n, how many element visits, on average, are necessary to find it using a linear search?

n / 2

The number of element visits for merge sort totals n + 5n log2 n. Which of the following is the appropriate big-Oh notation for merge sort?

n log2 n

How many comparisons does selection sort make when sorting an array of length n?

n( n + 1) / 2

Consider an array with n elements. If we visit each element n times, how many total visits will there be?

n^2

How would you create the class PackageSample in a package named bigjava.Chapter8?

package bigjava.chapter8; public class PackageSample {}

What allows the programmers to manipulate objects that share a set of tasks, even though the tasks are executed in different ways?

polymorphism

Which method of an exception object will provide information about the chain of method calls that led to the exception

printStackTrace()

With a few exceptions, what access should instance variables of classes always have?

private

To use a public variable or method outside of its class, you must ____ the name.

qualify

A version of which sort algorithm is used in the sort method in the Java Arrays class?

quicksort

The ____ method should be called whenever you modify the shapes that the paintComponent method draws.

repaint

Find the simplest order of growth of the following expression: n3 + log(n5).

θ(n3)


संबंधित स्टडी सेट्स

FL statutes, rules and regulations pertinent to life insurance--Chapter 11 Ouiz

View Set

Chapter 8 Global Business, international business chapter 7, International Finance 7&8 Q101-150

View Set

Chapter 12.4: POLITICAL TACTICS AND HOW TO USE THEM

View Set

Anatomy // Chapter 8 Special Senses

View Set