12 How many of these custom exceptions are unchecked exceptions?class ColoringException extends IOException {} class CursiveException extends WritingException {} class DrawingException extends IllegalStateException {} class SketchingException extends DrawingException {} class WritingException extends Exception {}NoneOneTwoThreeFourFive
13 How many lines of text does the following program print?package lighting; import java.io.IOException; public class Light { public static void main(String[] v) throws Exception { try { new Light().turnOn(); } catch (RuntimeException v) { // y1 System.out.println(v); throw new IOException(); // y2 } finally { System.out.println("complete"); } } public void turnOn() throws IOException { new IOException("Not ready"); // y3 } }One.Two.The code does not compile because of line y1.The code does not compile because of line y2.The code does not compile because of line y3.None of the above.
14 Which statements about try‐with‐resources are false? (Choose two.)If more than one resource is used, the resources are closed in the order they were created.Parentheses are used for the resource declaration section, even if more than one resource is used.If the try block and close() method both throw an exception, then the one thrown by the close() method is suppressed.A resource may be declared before it is used in a try‐with‐resources statement.Resources declarations are separated by commas.A catch block is not required.
15 How many lines of text does the following program print?package bee; class SpellingException extends RuntimeException {} public class SpellChecker { public final static void main(String… participants) { try { if(!"cat".equals("kat")) { new SpellingException(); } } catch (SpellingException | NullPointerException e) { System.out.println("Spelling problem!"); } catch (Exception e) { System.out.println("Unknown Problem!"); } finally { System.out.println("Done!"); } } }One.Two.Three.The code does not compile.None of the above.
16 Which of the following exception types must be handled or declared by the method in which they are thrown? (Choose three.)FileNotFoundExceptionClassCastExceptionErrorIOExceptionNullPointerExceptionException
17 What is the output of the following application?package bed; public class Sleep { public static void snore() { try { String sheep[] = new String[3]; System.out.print(sheep[3]); } catch (RuntimeException | Error e) { System.out.print("Awake!"); } finally { throw new Exception(); // x1 } } public static void main(String… sheep) { // x2 new Sleep().snore(); // x3 } }Awake!Awake! followed by a stack traceDoes not compile because of line x1Does not compile because of line x2Does not compile because of line x3None of the above
18 What is the output of the following code?class ProblemException extends Exception { ProblemException(Exception e) { super(e); } } class MajorProblemException extends ProblemException { MajorProblemException(String message) { super(message); } } public class Unfortunate { public static void main(String[] args) throws Exception { try { System.out.print(1); throw new MajorProblemException("Uh oh"); } catch (ProblemException | RuntimeException e) { System.out.print(2); try { throw new MajorProblemException("yikes"); } finally { System.out.print(3); } } finally { System.out.print(4); } } }123123 followed by an exception stack trace.12341234 followed by an exception stack trace.The code does not compile.None of the above.
19 Which statement best describes how a class that implements the AutoCloseable interface should be written? (Choose two.)The close() method is optional since the AutoCloseable interface defines a default implementation.The close() method should avoid modifying data after it has been run once.The close() method should not throw any exceptions.The close() method should throw an exception if there is a problem closing the resource.The close() method should return a status code.
20 Which of the following diagrams of java.lang classes shows the inheritance model properly?
21 Which exception classes, when inserted into the blank in the Problems class, allow the code to compile?class MissingMoneyException {} class MissingFoodException {} public class Problems { public void doIHaveAProblem() throws MissingMoneyException, MissingFoodException { System.out.println("No problems"); } public static void main(String[] s) throws ______________ { try { final Problems p = new Problems(); p.doIHaveAProblem(); } catch (Exception e) { throw e; } } }ExceptionRuntimeExceptionMissingFoodExceptionMissingMoneyException, MissingFoodExceptionMissingMoneyExceptionNone of the above
22 Which statements about Closeable and AutoCloseable are true? (Choose two.)AutoCloseable extends Closeable.Closeable extends AutoCloseable.The close() method in a class that implements AutoCloseable cannot throw an IOException.The close() method in a class that implements Closeable cannot throw an Exception.There is no difference; one was added for backward compatibility.Both have a generic return type.
23 Which expressions, when inserted into the blank in the following class, allow the code to compile? (Choose two.)package sun; import java.io.*; public class Beach { class TideException extends Exception {} public void surf() throws RuntimeException { try { throw new TideException(); } catch (_______________) {} } }Exception a | RuntimeException fIllegalStateException | TideException tTideException | IOException iTideException | Exception xError eException z
24 Which of the following are the best scenarios in which to use and catch an exception? (Choose two.)The computer caught fire.A network connection goes down.A caller passes invalid data to a method.The code does not compile.A method finishes sooner than expected.The program runs out of memory.
25 Which statement about the following program is correct?1: package dogpark; 2: public class Fetch { 3: public int play(String name) throws RuntimeException { 4: try { 5: throw new RuntimeException(name); 6: } catch (Throwable e) { 7: throw new RuntimeException(e); 8: } 9: } 10: public static final void main(String[] ball) 11: throws RuntimeException { 12: new Fetch().play("Webby"); 13: new Fetch().play("Georgette"); 14: } 15: }One exception is thrown to the caller at runtime.Two exceptions are thrown to the caller at runtime.More than two exceptions are thrown to the caller at runtime.The class does not compile because of the play() method.The class does not compile because of the main() method.None of the above.
26 What is the output of the following application?package body; import java.io.IOException; class Organ { public void operate() throws IOException { throw new RuntimeException("Not supported"); } } public class Heart extends Organ { public void operate() throws Exception { System.out.print("beat"); } public static void main(String… c) throws Exception { try { new Heart().operate(); } finally { System.out.print("!"); } } }beatbeat!Not supportedThe code does not compile.The code compiles, but a stack trace is printed at runtime.None of the above.
27 Which of the following are not true of using a try‐with‐resources statement? (Choose two.)It shortens the amount of code a developer must write.It is possible to close a resource before the end of the try block.Associated catch blocks are run before the declared resources have been closed.It is compatible with all classes that implement the Closeable interface.It is compatible with all classes that implement the AutoCloseable interface.It cannot be used with a finally block.
28 What is the result of compiling and executing the following class?package wind; public class Storm { public static void main(String… rain) throws Exception { var weatherTracker = new AutoCloseable() { public void close() throws RuntimeException { System.out.println("Thunder"); } }; try (weatherTracker) { System.out.println("Tracking"); } catch (Exception e) { System.out.println("Lightning"); } finally { System.out.println("Storm gone"); weatherTracker.close(); } } }It prints one line.It prints two lines.It prints three lines.It prints four lines.It does not compile due to an error in the declaration of the weatherTracker resource.It does not compile for a different reason.
29 How many of the following are valid exception declarations?class Error extends Exception {} class _X extends IllegalArgumentException {} class 2BeOrNot2Be