Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
FOR0283 Programming II: Homework Test 6 (Multiple-choice) Instructions: e-mail your answers to the class lecturer. Use subject header "FOR0283 multi 6". 1. An exception in Java is: a) a failure to compile the main method b) an unpredictable event at compile time c) an object generated when something unusual happens d) a class which contains the main method e) a failure to compile the class Exception 5. What is output by the following code? try { String c = "abcde"; int r1 = Integer.parseInt (c); } catch (ArrayIndexOutOfBoundsException e) {System.out.println ("Error!"); } catch (ArithmeticException e) {System.out.println ("Calculation Error!"); } System.out.println ("Finished!"); 2. Which set of Java keywords are used in exception handling: a) abstract class extends implements b) catch try thrown throws finally c) package private protected public d) catch try throw throws finally e) catch try throw throws final a) Finished! b) Error! c) Calculation Error! d) java.lang.NumberFormatException: abcde e) java.lang.Exception:parseInt 3. What is output by the following code? try { String a = "0"; //number 0 not letter O int r = Integer.parseInt (a) / Integer.parseInt (a); } catch (ArithmeticException e) {System.out.print("A");} catch (Exception e) {System.out.print("B"); } finally {System.out.print("C"); } System.out.println ("D"); 6. What message is output when you try to compile and run the following? try {String s = "fghijk"; int r = Integer.parseInt (s);} catch (Exception e) {System.out.println ("General Error");} catch (NumberFormatException e) {System.out.println ("Incorrect Format");} System.out.println ("Finished"); a) General Error b) Incorrect Format c) Finished d) General Error Incorrect Format e) java.lang.NumberFormatException has already been caught a) ABC b) ABD c) ACD d) ADC e) C 4. What is output by the following code? try { String c = "11"; //ones not lls int r1 = Integer.parseInt (c); } catch (NumberFormatException e) {System.out.println ("Incorrect Format!");} catch (Exception e) {System.out.println ("General Exception Error!"); } System.out.println ("Finished!"); 7. What is output by the following code? try { String s = "fghijk"; int r = Integer.parseInt (s);} catch (ArithmeticException e) { System.out.println ("Calculation Error");} catch (Exception e) {System.out.println ("General Error");} System.out.println ("Finished"); a) Calculation Error b) General Error c) Finished d) Calculation Error Finished e) General Error Finished a) Incorrect Format! b) Finished! c) General Exception Error! d) Incorrect Format! Finished! e) General Exception Error! Finished! 1 8. Which Javadoc tag is used to document exceptions? a) @tagException b) @ExceptionTag c) @throw d) @throws e) none of the above 9. Which of the following is a checked exception? a) FileNotFoundException b) NegativeArraySizeException c) NumberFormatException d) ArrayIndexOutOfBoundsException e) RuntimeException 10. Which package is the IOException class in? a) b) c) d) e) java.awt java.lang java.io java.security java.sql 2