Exam 12: Exceptions and Advanced File Io

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

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?

Free
(Multiple Choice)
4.8/5
(40)
Correct Answer:
Verified

D

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

Free
(Multiple Choice)
4.8/5
(35)
Correct Answer:
Verified

A

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

Free
(Multiple Choice)
4.9/5
(42)
Correct Answer:
Verified

C

The following catch statement can catch (Exception e){…}

(Multiple Choice)
4.9/5
(39)

In a catch statement,what does the following code do? System.out.println(e.getMessage());

(Multiple Choice)
5.0/5
(28)

If a method does not handle a possible checked exception,what must the method have?

(Multiple Choice)
5.0/5
(33)

This is a section of code that gracefully responds to exceptions when they are thrown.

(Multiple Choice)
4.9/5
(35)

The catch clause

(Multiple Choice)
4.8/5
(38)

The IllegalArgumentException class extends the RuntimeException class,and is therefore

(Multiple Choice)
4.7/5
(24)

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."); }

(Multiple Choice)
4.9/5
(39)

When writing a string to a binary file or reading a string from a binary file,it is recommended that you use

(Multiple Choice)
4.9/5
(36)

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

(Multiple Choice)
4.9/5
(33)

When an object is serialized,it is converted into a series of bytes that contain the object's data.

(True/False)
4.9/5
(33)

The throw statement informs the compiler that a method throws one or more exception.

(True/False)
4.9/5
(32)

A(n)________ is an object that is generated in memory as the result of an error or an unexpected event.

(Multiple Choice)
4.9/5
(38)

When deserializing an object using the readObject method,you must cast the return value to the desired class type.

(True/False)
4.8/5
(31)

What will be the result of the following code? FileOutputStream fstream new FileOutputStream("Output.dat"); DataOutputStream outputFile = new DataOutputStream(fstream);

(Multiple Choice)
4.8/5
(34)

The call stack is an internal list of all the methods that are currently executing.

(True/False)
4.7/5
(38)

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; }

(Multiple Choice)
5.0/5
(32)

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);

(Multiple Choice)
4.9/5
(38)
Showing 1 - 20 of 46
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)