Deck 12: Exceptions and Advanced File Io

Full screen (f)
exit full mode
Question
If the IOData.dat file does not exist,what will happen when the following statement is executed? RandomAccessFile randomFile =
New RandomAccessFile("IOData.dat","rw");

A) A FileNotFoundException will be thrown
B) An IOExcepton will be thrown
C) The file IOData.dat will be created
D) This is a critical error,the program will stop execution
Use Space or
up arrow
down arrow
to flip the card.
Question
All exceptions are instances of classes that extend this class.

A) RunTimeException
B) Throwable
C) Error
D) Exception
Question
In a try/catch construct,after the catch statement is executed

A) the program returns to the statement following the statement in which the exception occurred.
B) the program terminates.
C) the program resumes at the statement that immediately follows the try/catch construct.
D) the program resumes at the first statement of the try statement.
Question
All of the exceptions that you will handle are instances of classes that extend this class.

A) RunTimeException
B) IOException
C) Error
D) Exception
Question
A(n)________ is an object that is generated in memory as the result of an error or an unexpected event.

A) exception handler
B) exception
C) default exception handler
D) error message
Question
This is a section of code that gracefully responds to exceptions when they are thrown.

A) Thrown class
B) Default exception handler
C) Exception
D) Exception handler
Question
Look at the following code: FileInputStream fstream =
New FileInputStream("MyInfo.dat");
DataInputStream inputFile =
New DataInputStream(fstream);
This code can also be written as:

A) FileInputStream inputFile =
New FileInputStream(new DataInputStream("MyInfo.dat"));
B) DataInputStream inputFile =
New DataInputStream(new FileInputStream("MyInfo.dat"));
C) FileInputStream fstream =
New DataInputStream("InputFile.txt");
D) DataInputStream inputFile =
New DataInputStream("InputFile.txt");
Question
If the code in a method can potentially throw a checked exception,then that method must

A) handle the exception
B) have a throws clause listed in the method header
C) Neither a or b
D) Either a or b
Question
When writing a string to a binary file or reading a string from a binary file,it is recommended that you use

A) Methods that use UTF-8 encoding
B) The Scanner class methods
C) The FileReader and Writer class methods
D) The System.In and System.Out methods
Question
To read data from a binary file you create objects from the following classes:

A) FileInputStream and DataInputStream
B) File and PrintWriter
C) File and Scanner
D) BinaryFileReader and BinaryDataReader
Question
To write data to a binary file you create objects from the following classes:

A) File and PrintWriter
B) File and Scanner
C) FileOutputStream and DataOutputStream
D) BinaryFileWriter and BinaryDataWriter
Question
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;
}
}
What will be the value of totalIncome after the following values are read from the file?
2)5
8)5
3)0
5)5
Abc
1)0

A) 19.5
B) 0.0
C) 35.5
D) 75.0
Question
Why does the following code cause a compiler error? try
{
Number = Integer.parseInt(str);
}
Catch (IllegalArgumentException e)
{
System.out.println("Bad number format.");
}
Catch (NumberFormatException e)
{
System.out.println(str + " is not a number.");
}

A) Because you can have only one catch clause in a try statement.
B) Because NumberFormatException inherits from IllegalArgumentException.The code should handle NumberFormatException before IllegalArgumentException.
C) Because the Integer.parseInt method does not throw a NumberFormatException.
D) Because the Integer.parseInt method does not throw an IllegalArgumentException.
Question
The following catch statement can catch (Exception e){…}

A) can handle all exceptions that are instances of the Exception class,but not a subclass of Exception.
B) handle all throwable objects by using polymorphic reference as a parameter in the catch clause.
C) handle all exceptions that are instances of the Exception class or a subclass of Exception.
D) is an error since no objects are instantiated in the Exception class.
Question
When an exception is thrown,

A) it must always be handled by the method that throws it.
B) the program terminates even if the exception is handled.
C) it must be handled by the program or by the default exception handler.
D) it may be ignored.
Question
Given the following constructor code,which of the statements are true? public Book(String ISBNOfBook,double priceOfBook,
Int numberOrderedOfBook)
{
If (ISBNOfBook == "")
Throw new BlankISBN();
If (priceOfBook < 0)
Throw new NegativePrice(priceOfBook);
If (numberedOrderedOfBook < 0)
Throw new NegativeNumberOrdered(numberOrderedv);
ISBN = ISBNOfBook;
Price = priceOfBook;
NumberedOrdered = numberOrderedOfBook;
}

A) There is an error: a throws clause should be added to the constructor header.
B) Classes extending the Exception class should be created for each of the custom exceptions that are thrown in the constructor.
C) The calling method must handle the exceptions thrown in the constructor,or have its own throws clause specifying them.
D) All of the above.
Question
An exception's default error message can be retrieved using this method.

A) getMessage()
B) getErrorMessage()
C) getDefaultMessage()
D) getDefaultErrorMessage()
Question
The IllegalArgumentException class extends the RuntimeException class,and is therefore

A) a checked exception class.
B) an unchecked exception class
C) never used directly
D) None of the above
Question
What will be the result of the following statements? FileInputStream fstream =
New FileInputStream("DataIn.dat");
DataInputStream inFile =
New DataInputStream(fstream);

A) The inFile variable will reference an object that is able to read only text data from the Input.dat file.
B) The inFile variable will reference an object that is able to read binary data from the Input.dat file.
C) The inFile variable will reference an object that is able to write binary data to the Input.dat file.
D) The inFile variable will reference an object that is able to read random access data from the Input.dat file
Question
If,within one try statement you want to have catch clauses of the following types,in which order should they appear in your program: (1)Exception
(2)IllegalArgumentException
(3)RuntimeException
(4)Throwable

A) 1,2,3,4
B) 2,3,1,4
C) 4,1,3,2
D) 3,1,2,4
Question
In a catch statement,what does the following code do? System.out.println(e.getMessage());

A) It prints the stack trace.
B) It prints the error message for an exception.
C) It prints the code that caused the exception.
D) It overrides the toString method
Question
What will be the result of the following code? FileOutputStream fstream new FileOutputStream("Output.dat");
DataOutputStream outputFile = new DataOutputStream(fstream);

A) The outputFile variable will reference an object that is able to write text data only to the Output.dat file.
B) The outputFile variable will reference an object that is able to write binary data to the Output.dat file.
C) The outputFile variable will reference an object that is able to read binary data from the Output.dat file.
D) The outputFile variable will reference an object that is able to write to Output.dat as a random access file.
Question
If you want to append data to the existing binary file,BinaryFile.dat,use the following statements to open the file.

A) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat");
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
B) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat",false);
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
C) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat",true);
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
D) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat");
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream,true);
Question
When the code in a try block may throw more than one type of exception,you need to write a catch clause for each type of exception that could potentially be thrown.
Question
What will the following code display? String input = "99#7";
Int number;
Try
{
Number = Integer.parseInt(input);
}
Catch(NumberFormatException ex)
{
Number = 0;
}
Catch(RuntimeException ex)
{
Number = 1;
}
Catch(Exception ex)
{
Number = -1;
}
System.out.println(number);

A) 99
B) 997
C) 0
D) 1
Question
In order for an object to be serialized,its class must implement this interface.

A) Serial
B) Writable
C) Serializable
D) ObjectOutputStream
Question
If a method does not handle a possible checked exception,what must the method have?

A) A catch clause in its header
B) A try/catch clause in its header
C) A try clause in its header
D) A throws clause in its header
Question
Unchecked exceptions are those that inherit from

A) the Error class or the RuntimeException class.
B) the Error class or the Exception class.
C) the Exception Class or the RuntimeException class.
D) only the Error class.
Question
When you write a method that throws a checked exception,you must

A) have a throws clause in the method header.
B) override the default error method.
C) use each class only once in a method.
D) ensure that the error will occur at least once each time the program is executed.
Question
The catch clause

A) follows the try clause.
B) starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable.
C) contains code to gracefully handle the exception type listed in the parameter list.
D) All of the above.
Question
If the program does not handle an unchecked exception,

A) the exception is ignored.
B) the program is halted and the default exception handler handles the exception.
C) the program must handle the exception.
D) this will cause a compilation error.
Question
The call stack is an internal list of all the methods that are currently executing.
Question
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) 4,3,2,1
B) 2,3,1,4
C) 4,1,3,2
D) 3,1,2,4
Question
Assume that the classes BlankISBN,NegativePrice,and NegativeNumberOrdered are exception classes that inherit from Exception.The following code is a constructor for the Book class.What must be true about any method that instantiates the Book class with this constructor? public Book(String ISBNOfBook,double priceOfBook,
Int numberOrderedOfBook)throws BlankISBN,
NegativePrice,
NegativeNumberOrdered
{
If (ISBNOfBook == "")
Throw new BlankISBN();
If (priceOfBook < 0)
Throw new NegativePrice(priceOfBook);
If (numberedOrderedOfBook < 0)
Throw new NegativeNumberOrdered(numberOrderedv);
ISBN = ISBNOfBook;
Price = priceOfBook;
NumberedOrdered = numberOrderedOfBook;
}

A) It must call the constructor with valid data or a compiler error will occur.
B) It must contain an inner class that extends the IOException class.
C) It must handle all of the possible exceptions thrown by the constructor or have its own throws clause specifying them.
D) All of the above.
Question
To serialize an object and write it to the file,use this method of the ObjectOutputStream class.

A) SerializeObject
B) WriteObject
C) Serialize
D) SerializeAndWrite
Question
The throw statement informs the compiler that a method throws one or more exception.
Question
A class must implement the Serializable interface in order for objects of the class to be serialized.
Question
If a random access file contains a stream of characters,which of the following would you use to set the pointer on the fifth character?

A) file.seek(4);
B) file.seek(5);
C) file.seek(9);
D) file.seek(8);
Question
When an exception is thrown by code in the try block,the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to

A) each catch clause that can handle the exception.
B) the last catch clause that can handle the exception.
C) the first catch clause that can handle the exception.
D) If there are two or more catch clauses that can handle the exception,the program halts.
Question
Classes that inherit from the Error class are

A) for exceptions that are thrown when a critical error occurs,and the application program should not try to handle them.
B) for exceptions that are thrown when a critical error occurs,and the application program should try to handle them.
C) for exceptions that are thrown when an IOException occurs,and the application program should not try to handle them.
D) for exceptions that are thrown when an IOException error occurs,and the application program should try to handle them.
Question
When deserializing an object using the readObject method,you must cast the return value to the desired class type.
Question
A catch clause that uses a parameter variable of the Exception type is capable of catching any exception that extends the Error class.
Question
The throws clause causes an exception to be thrown.
Question
When an exception is thrown by a method that is executing under several layers of method calls,a stack trace indicates the method executing when an exception occurred and all of the methods that were called in order go execute that method.
Question
If class,SerializedClass,contains references to objects of other classes as fields,those classes must also implement the Serializable interface in order to be serialized.
Question
When an object is serialized,it is converted into a series of bytes that contain the object's
data.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/46
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 12: Exceptions and Advanced File Io
1
If the IOData.dat file does not exist,what will happen when the following statement is executed? RandomAccessFile randomFile =
New RandomAccessFile("IOData.dat","rw");

A) A FileNotFoundException will be thrown
B) An IOExcepton will be thrown
C) The file IOData.dat will be created
D) This is a critical error,the program will stop execution
C
2
All exceptions are instances of classes that extend this class.

A) RunTimeException
B) Throwable
C) Error
D) Exception
B
3
In a try/catch construct,after the catch statement is executed

A) the program returns to the statement following the statement in which the exception occurred.
B) the program terminates.
C) the program resumes at the statement that immediately follows the try/catch construct.
D) the program resumes at the first statement of the try statement.
C
4
All of the exceptions that you will handle are instances of classes that extend this class.

A) RunTimeException
B) IOException
C) Error
D) Exception
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
5
A(n)________ is an object that is generated in memory as the result of an error or an unexpected event.

A) exception handler
B) exception
C) default exception handler
D) error message
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
6
This is a section of code that gracefully responds to exceptions when they are thrown.

A) Thrown class
B) Default exception handler
C) Exception
D) Exception handler
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
7
Look at the following code: FileInputStream fstream =
New FileInputStream("MyInfo.dat");
DataInputStream inputFile =
New DataInputStream(fstream);
This code can also be written as:

A) FileInputStream inputFile =
New FileInputStream(new DataInputStream("MyInfo.dat"));
B) DataInputStream inputFile =
New DataInputStream(new FileInputStream("MyInfo.dat"));
C) FileInputStream fstream =
New DataInputStream("InputFile.txt");
D) DataInputStream inputFile =
New DataInputStream("InputFile.txt");
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
8
If the code in a method can potentially throw a checked exception,then that method must

A) handle the exception
B) have a throws clause listed in the method header
C) Neither a or b
D) Either a or b
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
9
When writing a string to a binary file or reading a string from a binary file,it is recommended that you use

A) Methods that use UTF-8 encoding
B) The Scanner class methods
C) The FileReader and Writer class methods
D) The System.In and System.Out methods
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
10
To read data from a binary file you create objects from the following classes:

A) FileInputStream and DataInputStream
B) File and PrintWriter
C) File and Scanner
D) BinaryFileReader and BinaryDataReader
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
11
To write data to a binary file you create objects from the following classes:

A) File and PrintWriter
B) File and Scanner
C) FileOutputStream and DataOutputStream
D) BinaryFileWriter and BinaryDataWriter
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
12
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;
}
}
What will be the value of totalIncome after the following values are read from the file?
2)5
8)5
3)0
5)5
Abc
1)0

A) 19.5
B) 0.0
C) 35.5
D) 75.0
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
13
Why does the following code cause a compiler error? try
{
Number = Integer.parseInt(str);
}
Catch (IllegalArgumentException e)
{
System.out.println("Bad number format.");
}
Catch (NumberFormatException e)
{
System.out.println(str + " is not a number.");
}

A) Because you can have only one catch clause in a try statement.
B) Because NumberFormatException inherits from IllegalArgumentException.The code should handle NumberFormatException before IllegalArgumentException.
C) Because the Integer.parseInt method does not throw a NumberFormatException.
D) Because the Integer.parseInt method does not throw an IllegalArgumentException.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
14
The following catch statement can catch (Exception e){…}

A) can handle all exceptions that are instances of the Exception class,but not a subclass of Exception.
B) handle all throwable objects by using polymorphic reference as a parameter in the catch clause.
C) handle all exceptions that are instances of the Exception class or a subclass of Exception.
D) is an error since no objects are instantiated in the Exception class.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
15
When an exception is thrown,

A) it must always be handled by the method that throws it.
B) the program terminates even if the exception is handled.
C) it must be handled by the program or by the default exception handler.
D) it may be ignored.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
16
Given the following constructor code,which of the statements are true? public Book(String ISBNOfBook,double priceOfBook,
Int numberOrderedOfBook)
{
If (ISBNOfBook == "")
Throw new BlankISBN();
If (priceOfBook < 0)
Throw new NegativePrice(priceOfBook);
If (numberedOrderedOfBook < 0)
Throw new NegativeNumberOrdered(numberOrderedv);
ISBN = ISBNOfBook;
Price = priceOfBook;
NumberedOrdered = numberOrderedOfBook;
}

A) There is an error: a throws clause should be added to the constructor header.
B) Classes extending the Exception class should be created for each of the custom exceptions that are thrown in the constructor.
C) The calling method must handle the exceptions thrown in the constructor,or have its own throws clause specifying them.
D) All of the above.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
17
An exception's default error message can be retrieved using this method.

A) getMessage()
B) getErrorMessage()
C) getDefaultMessage()
D) getDefaultErrorMessage()
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
18
The IllegalArgumentException class extends the RuntimeException class,and is therefore

A) a checked exception class.
B) an unchecked exception class
C) never used directly
D) None of the above
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
19
What will be the result of the following statements? FileInputStream fstream =
New FileInputStream("DataIn.dat");
DataInputStream inFile =
New DataInputStream(fstream);

A) The inFile variable will reference an object that is able to read only text data from the Input.dat file.
B) The inFile variable will reference an object that is able to read binary data from the Input.dat file.
C) The inFile variable will reference an object that is able to write binary data to the Input.dat file.
D) The inFile variable will reference an object that is able to read random access data from the Input.dat file
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
20
If,within one try statement you want to have catch clauses of the following types,in which order should they appear in your program: (1)Exception
(2)IllegalArgumentException
(3)RuntimeException
(4)Throwable

A) 1,2,3,4
B) 2,3,1,4
C) 4,1,3,2
D) 3,1,2,4
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
21
In a catch statement,what does the following code do? System.out.println(e.getMessage());

A) It prints the stack trace.
B) It prints the error message for an exception.
C) It prints the code that caused the exception.
D) It overrides the toString method
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
22
What will be the result of the following code? FileOutputStream fstream new FileOutputStream("Output.dat");
DataOutputStream outputFile = new DataOutputStream(fstream);

A) The outputFile variable will reference an object that is able to write text data only to the Output.dat file.
B) The outputFile variable will reference an object that is able to write binary data to the Output.dat file.
C) The outputFile variable will reference an object that is able to read binary data from the Output.dat file.
D) The outputFile variable will reference an object that is able to write to Output.dat as a random access file.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
23
If you want to append data to the existing binary file,BinaryFile.dat,use the following statements to open the file.

A) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat");
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
B) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat",false);
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
C) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat",true);
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream);
D) FileOutputStream fstream =
New FileOutputStream("BinaryFile.dat");
DataOutputStream binaryOutputFile =
New DataOutputStream(fstream,true);
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
24
When the code in a try block may throw more than one type of exception,you need to write a catch clause for each type of exception that could potentially be thrown.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
25
What will the following code display? String input = "99#7";
Int number;
Try
{
Number = Integer.parseInt(input);
}
Catch(NumberFormatException ex)
{
Number = 0;
}
Catch(RuntimeException ex)
{
Number = 1;
}
Catch(Exception ex)
{
Number = -1;
}
System.out.println(number);

A) 99
B) 997
C) 0
D) 1
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
26
In order for an object to be serialized,its class must implement this interface.

A) Serial
B) Writable
C) Serializable
D) ObjectOutputStream
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
27
If a method does not handle a possible checked exception,what must the method have?

A) A catch clause in its header
B) A try/catch clause in its header
C) A try clause in its header
D) A throws clause in its header
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
28
Unchecked exceptions are those that inherit from

A) the Error class or the RuntimeException class.
B) the Error class or the Exception class.
C) the Exception Class or the RuntimeException class.
D) only the Error class.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
29
When you write a method that throws a checked exception,you must

A) have a throws clause in the method header.
B) override the default error method.
C) use each class only once in a method.
D) ensure that the error will occur at least once each time the program is executed.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
30
The catch clause

A) follows the try clause.
B) starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable.
C) contains code to gracefully handle the exception type listed in the parameter list.
D) All of the above.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
31
If the program does not handle an unchecked exception,

A) the exception is ignored.
B) the program is halted and the default exception handler handles the exception.
C) the program must handle the exception.
D) this will cause a compilation error.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
32
The call stack is an internal list of all the methods that are currently executing.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
33
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) 4,3,2,1
B) 2,3,1,4
C) 4,1,3,2
D) 3,1,2,4
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
34
Assume that the classes BlankISBN,NegativePrice,and NegativeNumberOrdered are exception classes that inherit from Exception.The following code is a constructor for the Book class.What must be true about any method that instantiates the Book class with this constructor? public Book(String ISBNOfBook,double priceOfBook,
Int numberOrderedOfBook)throws BlankISBN,
NegativePrice,
NegativeNumberOrdered
{
If (ISBNOfBook == "")
Throw new BlankISBN();
If (priceOfBook < 0)
Throw new NegativePrice(priceOfBook);
If (numberedOrderedOfBook < 0)
Throw new NegativeNumberOrdered(numberOrderedv);
ISBN = ISBNOfBook;
Price = priceOfBook;
NumberedOrdered = numberOrderedOfBook;
}

A) It must call the constructor with valid data or a compiler error will occur.
B) It must contain an inner class that extends the IOException class.
C) It must handle all of the possible exceptions thrown by the constructor or have its own throws clause specifying them.
D) All of the above.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
35
To serialize an object and write it to the file,use this method of the ObjectOutputStream class.

A) SerializeObject
B) WriteObject
C) Serialize
D) SerializeAndWrite
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
36
The throw statement informs the compiler that a method throws one or more exception.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
37
A class must implement the Serializable interface in order for objects of the class to be serialized.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
38
If a random access file contains a stream of characters,which of the following would you use to set the pointer on the fifth character?

A) file.seek(4);
B) file.seek(5);
C) file.seek(9);
D) file.seek(8);
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
39
When an exception is thrown by code in the try block,the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to

A) each catch clause that can handle the exception.
B) the last catch clause that can handle the exception.
C) the first catch clause that can handle the exception.
D) If there are two or more catch clauses that can handle the exception,the program halts.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
40
Classes that inherit from the Error class are

A) for exceptions that are thrown when a critical error occurs,and the application program should not try to handle them.
B) for exceptions that are thrown when a critical error occurs,and the application program should try to handle them.
C) for exceptions that are thrown when an IOException occurs,and the application program should not try to handle them.
D) for exceptions that are thrown when an IOException error occurs,and the application program should try to handle them.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
41
When deserializing an object using the readObject method,you must cast the return value to the desired class type.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
42
A catch clause that uses a parameter variable of the Exception type is capable of catching any exception that extends the Error class.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
43
The throws clause causes an exception to be thrown.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
44
When an exception is thrown by a method that is executing under several layers of method calls,a stack trace indicates the method executing when an exception occurred and all of the methods that were called in order go execute that method.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
45
If class,SerializedClass,contains references to objects of other classes as fields,those classes must also implement the Serializable interface in order to be serialized.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
46
When an object is serialized,it is converted into a series of bytes that contain the object's
data.
Unlock Deck
Unlock for access to all 46 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 46 flashcards in this deck.