Question: 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 =

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.

1 points

Question 11

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

getMessage

throwMessage

printStackTrace

toString

1 points

Question 12

import java.util.*; public class ExceptionExample1 { static Scanner console = new Scanner(System.in); public static void main(String[] args) { int dividend, divisor, quotient; try { System.out.print("Enter dividend: "); dividend = console.nextInt(); System.out.println(); System.out.print("Enter divisor: "); divisor = console.nextInt(); System.out.println(); quotient = dividend / divisor; System.out.println("quotient = " + quotient); } catch (ArithmeticException aeRef) { System.out.println("Exception" + aeRef.toString()); } catch (InputMismatchException imeRef) { System.out.println("Exception " + imeRef.toString()); } catch( IOException ioeRef) { System.out.println("Exception " + ioeRef.toString()); } } } Which of the following will cause the first exception to occur in the code in the accompanying figure?

If the divisor is zero

If the dividend is zero

If the quotient is zero

This code will not compile, so an exception cannot be triggered.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!