Question 13 import java.util.*; public class ExceptionExample1 { static Scanner
ID: 3823621 • Letter: Q
Question
Question 13
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 inputs would be caught by the second catch block in the program in the accompanying figure?
0
10
h3
-1
1 points
Question 14
Which of the following is NOT a typical action of the catch block?
Completely handling the exception
Partially processing of the exception
Rethrowing the same exception for the calling environment
Throwing the exception
1 points
Question 15
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?
The program ignores the exception.
The program will not compile without a complete try/catch structure.
The program terminates immediately.
The program throws an exception and proceeds to execute the finally block.
1 points
Question 16
Which of the following exceptions might be thrown by the methods of the class String?
NullPointerException
FileNotFoundException
NoSuchElementsException
NumberFormatException
1 points
Question 17
How many finally blocks can there be in a try/catch structure?
There must be one finally block.
There can be one finally block following each catch block.
There can be zero or one finally blocks following the last catch block.
There is no limit to the number of finally blocks following the last catch block.
1 points
Question 18
The class RuntimeException is the superclass of which of the following classes?
NullPointerException
NoSuchMethodException
IllegalAccessException
NoSuchFileException
1 points
Question 19
Which of the following statements is true?
The class Exception, which is derived from the class Object, is the superclass of the class Throwable.
The class Throwable, which is derived from the class Exception, is the superclass of the class Object.
The class Throwable, which is derived from the class Object, is the superclass of the class Exception.
None of these
1 points
Question 20
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 method throws the second exception in the code in the accompanying figure?
nextInt
toString
println
nextLine
0
10
h3
-1
Explanation / Answer
13) h3 - Because the input provided is not of integer type.
14) Rethrowing the same exception for the calling environment
15) The program throws an exception and proceeds to execute the finally block.
Because finally block is always executed and it is not necessary that catch follows try block.
16) NullPointerException and NumberFormatException
17)There must be one finally block. - There is always 1 finally block associated with try catch block
18)NullPointerException and IllegalAccessException occur at runtime . NoSuchMethodException is mostly caught at compile time but in few scenarios can occur at runtime also.
19)The class Throwable, which is derived from the class Object, is the superclass of the class Exception.
20)nextLine :- Because this returns the String value and not Integer Value
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.