Java: Chapter 11 Quiz- Questions and
Answers| Latest Update
If, within one try statement you want to have catch clauses that catch exceptions of the
following types, in which order should they appear in your program?
(1) Throwable
(2) Exception
(3) RuntimeException
(4) NumberFormatException
A) 3, 1, 2, 4
B) 4, 3, 2, 1
C) 2, 3, 1, 4
D) 4, 1, 3, 2 ✔️✔️B) 4, 3, 2, 1
If you want to append data to the existing binary file, BinaryFile.dat, use the following
statements to open the file.
A) Image 3.jpg ✔️✔️A) Image 3.jpg
If your code does not handle and exception when it is thrown, this prints an error message and
crashes the program.
A) try statement
B) multi-catch
C) Java error handler
,D) default exception handler ✔️✔️D) default exception handler
In a catch statement, what does the following code do?
System.out.println(e.getMessage());
A) It overrides the toString method.
B) It prints the code that caused the exception.
C) It prints the stack trace.
D) It prints the error message for an exception. ✔️✔️D) It prints the error message for an
exception.
In a multi-catch, (introduced in Java 7) the exception types are separated in the catch clause by
this symbol:
A) *
B) &
C) ?
D) | ✔️✔️D) |
In a try/catch construct, after the catch statement is executed:
A) the program resumes at the statement that immediately follows the try / catch construct
B) the program terminates
C) the program resumes at the first statement of the try statement
D) the program returns to the statement following the statement in which the exception
occurred ✔️✔️A) the program resumes at the statement that immediately follows the try / catch
construct
, In order for an object to be serialized, its class must implement this interface.
A) Writable
B) ObjectOutputStream
C) Serial
D) Serializable ✔️✔️D) Serializable
In the following code, assume that inputFile references a Scanner object that has been
successfully used to open a file:
double totalIncome = 0.0;
while (inputFile.hasNext())
{
try
{
totalIncome += inputFile.nextDouble();
}
catch(InputMismatchException e)
{
System.out.println("Non-numeric data encountered " + "in the file.");
inputFile.nextLine();
}
finally
{
totalIncome = 35.5;
}
Answers| Latest Update
If, within one try statement you want to have catch clauses that catch exceptions of the
following types, in which order should they appear in your program?
(1) Throwable
(2) Exception
(3) RuntimeException
(4) NumberFormatException
A) 3, 1, 2, 4
B) 4, 3, 2, 1
C) 2, 3, 1, 4
D) 4, 1, 3, 2 ✔️✔️B) 4, 3, 2, 1
If you want to append data to the existing binary file, BinaryFile.dat, use the following
statements to open the file.
A) Image 3.jpg ✔️✔️A) Image 3.jpg
If your code does not handle and exception when it is thrown, this prints an error message and
crashes the program.
A) try statement
B) multi-catch
C) Java error handler
,D) default exception handler ✔️✔️D) default exception handler
In a catch statement, what does the following code do?
System.out.println(e.getMessage());
A) It overrides the toString method.
B) It prints the code that caused the exception.
C) It prints the stack trace.
D) It prints the error message for an exception. ✔️✔️D) It prints the error message for an
exception.
In a multi-catch, (introduced in Java 7) the exception types are separated in the catch clause by
this symbol:
A) *
B) &
C) ?
D) | ✔️✔️D) |
In a try/catch construct, after the catch statement is executed:
A) the program resumes at the statement that immediately follows the try / catch construct
B) the program terminates
C) the program resumes at the first statement of the try statement
D) the program returns to the statement following the statement in which the exception
occurred ✔️✔️A) the program resumes at the statement that immediately follows the try / catch
construct
, In order for an object to be serialized, its class must implement this interface.
A) Writable
B) ObjectOutputStream
C) Serial
D) Serializable ✔️✔️D) Serializable
In the following code, assume that inputFile references a Scanner object that has been
successfully used to open a file:
double totalIncome = 0.0;
while (inputFile.hasNext())
{
try
{
totalIncome += inputFile.nextDouble();
}
catch(InputMismatchException e)
{
System.out.println("Non-numeric data encountered " + "in the file.");
inputFile.nextLine();
}
finally
{
totalIncome = 35.5;
}