Chapter 12 AP Comp Sci Review

Ace your homework & exams now with Quizwiz!

The StringIndexOutOfBoundsException could be thrown by the method parseInt of the class Integer.

False

The class Object is derived from the class Throwable.

False

The class RuntimeException is part of the package java.io.

False

The class Throwable is derived from the class Exception.

False

The methods getMessage and printStackTrace are private methods of the class Throwable.

False

The order in which catch blocks are placed in a program has no impact on which catch block is executed.

False

The try block contains statements that should be executed regardless of whether or not an exception occurs.

False

Which of the following methods prints a list of the methods that were called before the exception was thrown?

c. printStackTrace()

The class exception and its subclasses are designed to catch Exceptions that should be caught and processed during program execution

true

Statements that might generate an exception are placed in a catch block.

False

How many constructors does the class Exception have?

C. 2

Which of the following statements is true?

C. The class Throwable, which is derived from the class Object, is the superclass of the class Exception.

A checked exception is any exception checked for by the programmer.

False

An unchecked exception is any exception that causes a program to terminate.

False

Every program with a try block must end with a finally block.

False

NoSuchFileException is a method of the class Exception.

False

During program execution, if division by zero occurs with integer values and is not addressed by the program, then the program terminates with an error message indicating an attempt to divide by zero.

True

For interfaces such as WindowListener that contain more than one method, Java provides the class WindowAdapter.

True

If an exception occurs in a try block and that exception is caught by a catch block, then the remaining catch blocks associated with that try block are ignored.

True

If there is a finally block after the last catch block, the finally block always executes.

True

If you have a reference to an exception object, you can use the reference to throw the exception

True

If you have created an exception class, you can define other exception classes extending the definition of the exception class you created.

True

Making a reference to an object that has not yet been instantiated would throw an exception from the NullPointerException class.

True

To handle window events you first create a class that implements the interface WindowListener and then you create and register objects of that class.

True

When an exception occurs in a method, you can use the method printStackTrace to determine the order in which the methods were called and where the exception was handled.

True

When an exception occurs, an object of a specific exception class is created by the system.

True

The class RuntimeException is the superclass of which of the following classes?

a. NullPointerException

Which of the following is an exception thrown by the methods of the class String?

a. NullPointerException

(see ExceptionExample1) Which of the following will cause the first exception to occur in the code above?

a. if the divisor is zero

See ExceptionExample1 Which method throws the second exception in the code above?

a. nextInt

Code Which exception-handling technique is the code above using?

b. Fix the error and continue

int number; boolean done = false; do { try { System.out.print("Enter an integer: "); number = console.nextInt(); System.out.println(); done = true; System.out.println("number = " + number); } catch (InputMismatchException imeRef) { str = console.next(); System.out.println("Exception " + imeRef.toString() + " " + str); } } while (!done); What is most likely the type of exception in the code above?

b. InputMismatch Exception

Which of the following statements is NOT true about creating your own exceptions?

b. The exception class that you define extends either the class Throwable or one of its subclasses.

code How many times will the code in the try block above execute?

b. Until the user inputs a valid integer

For the interface WindowListener that contains more than one method, Java provides the class ____.

b. WindowAdapter

An exception that can be analyzed by the compiler is a(n) ____.

b. checked exception

A message string is returned by which method of an Exception object?

b. getMessage()

Which of the following is NOT a method of the class Throwable?

b. throwMessage

Which class of exceptions is NOT checked?

c. RuntimeException

How many finally blocks can there be in a try/catch structure?

c. There can be 0 or 1 following the last catch block.

What can a method do with a checked exception?

c. Throw the exception to the method that called this method, or handle the exception in a catch block.

(see ExceptionExample1) Which of the following inputs would be caught by the second catch block in the program above?

c. h3

When is a finally{} block executed?

d. Always after the execution of a try block, regardless of whether or not an exception is thrown

What happens in a method if there is an exception thrown in a try block but there is no catch block following the try block?

d. The program throws an exception and proceeds to execute the finally block.

Which of the following is NOT a typical action of the catch Block?

d. Throwing the exception

If a negative value is used for an array index, ____.

d. an IndexOutOfBoundsException is thrown

If in the heading of a catch block you can declare an exception using the class Exception, then that catch block can catch all types of exceptions because the class Exception is the superclass of all exception classes.

true

The class Exception contains two constructors.

true


Related study sets

Consumer Behavior Chapter 11 (Groups and Social Media)

View Set

Finance 300 Practice Questions Chapter 8

View Set