Question: What can a method do with a checked exception? Check the exception or ignore it. Return the exception to the sender or handle it in
What can a method do with a checked exception?
| Check the exception or ignore it. | ||
| Return the exception to the sender or handle it in a catch block. | ||
| Throw the exception to the method that called this method, or handle the exception in a catch block. | ||
| Handle the exception in the try block or handle the exception in the catchblock. |
1 points
Question 2
To handle window events, if the class containing the application program does not extend the definition of another class, you can make that class extend the definition of the class ____.
| MouseAdapter | ||
| Adapter | ||
| WindowAdapter | ||
| WindowListener |
1 points
Question 3
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 the most likely type of exception in the code in the accompanying figure?
| IllegalArgumentException | ||
| InputMismatchException | ||
| FileNotFoundException | ||
| NumberFormatException |
1 points
Question 4
A message is returned by which method of an Exception object?
| printMessage() | ||
| getMessage() | ||
| printStackTrace() | ||
| traceMessage() |
1 points
Question 5
Which class of exceptions is NOT checked?
| FileNotFoundException | ||
| ArithmeticException | ||
| RuntimeException | ||
| All exceptions are checked. |
1 points
Question 6
If a negative value is used for an array index, ____.
| a NumberFormatException is thrown | ||
| the program terminates automatically without throwing an exception | ||
| the last index of the array is automatically accessed instead | ||
| an ArrayIndexOutOfBoundsException is thrown |
1 points
Question 7
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); How many times will the code in the try block in the accompanying figure execute?
| Until the user specifies that he/she wants to quit the program | ||
| Until the user inputs a valid integer | ||
| If there is an exception thrown, it will execute just once because the program will terminate at that point. | ||
| Zero times; the program will terminate before it reaches the try block. |
1 points
Question 8
How many constructors does the class Exception have?
| zero | ||
| one | ||
| two | ||
| three |
1 points
Question 9
Which of the following methods prints a list of the methods that were called before the exception was thrown?
| getMessage() | ||
| printCalledMethods() | ||
| printStackTrace() | ||
| traceMethodStack() |
1 points
Question 10
Which of the following statements is NOT true about creating your own exceptions?
| Typically, constructors are the only methods that you include when you define your own exception class. | ||
| The exception class that you define extends either the class Throwable or one of its subclasses. | ||
| If you have created an exception class, you can define other exception classes by extending the definition of the exception class you created. | ||
| You must throw your own exceptions using the throw statement. |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
