30 If a try statement has catch blocks for both ClassCastException and RuntimeException, then which of the following statements is correct?The catch blocks for these two exception types can be declared in any order.A try statement cannot be declared with these two catch block types because they are incompatible.The catch block for ClassCastException must appear before the catch block for RuntimeException.The catch block for RuntimeException must appear before the catch block for ClassCastException.None of the above.
31 Assuming Scanner is a valid class that implements AutoCloseable, what is the expected output of the following application?package castles; import java.util.Scanner; public class Fortress { public void openDrawbridge() throws Exception { // p1 try { throw new Exception("Circle"); // p2 } catch (Exception | Error e) { System.out.print("Opening!"); } finally { System.out.print("Walls"); } } public static void main(String[] moat) { try (var e = new Scanner(System.in)) { new Fortress().openDrawbridge(); // p3 } } }Opening!WallsThe code does not compile because of line p1.The code does not compile because of line p2.The code does not compile because of line p3.The code compiles, but a stack trace is printed at runtime.None of the above.
32 What is the output of the following application?package game; public class BasketBall { public static void main(String[] dribble) { try { System.out.print(1); throw new ClassCastException(); } catch (ArrayIndexOutOfBoundsException ex) { System.out.print(2); } catch (Throwable ex) { System.out.print(3); } finally { System.out.print(4); } System.out.print(5); } }14513451235The code does not compile.The code compiles but throws an exception at runtime.None of the above.
33 Which of the following statements about finally blocks are true? (Choose two.)Every line of the finally block is guaranteed to be executed.The finally block is executed only if the related catch block is also executed.The finally statement requires curly braces, {}.A finally block cannot throw an exception.The first line of a finally block is guaranteed to be executed.A finally block can only throw unchecked exceptions.
34 What is the output of the following application?package signlanguage; import java.io.Closeable; class ReadSign implements Closeable { public void close() {} public String get() {return "Hello";} } class MakeSign implements AutoCloseable { public void close() {} public void send(String message) { System.out.print(message); } } public class Translate { public static void main(String… hands) { try (ReadSign r = new ReadSign(); MakeSign w = new MakeSign();) { w.send(r.get()); } } }HelloThe code does not compile because of the ReadSign class.The code does not compile because of the MakeSign class.The code does not compile because of the Translate class.The code does not compile because of the try‐with‐resources statement.None of the above.
35 What is the output of the following application?package what; class FunEvent implements AutoCloseable { private final int value; FunEvent(int value) { this.value = value; } public void close() { System.out.print(value); } } public class Happening { public static void main(String… lots) { FunEvent e = new FunEvent(1); try (e; var f = new FunEvent(8)) { System.out.print("2"); throw new ArithmeticException(); } catch (Exception x) { System.out.print("3"); } finally { System.out.print("4"); } } }2421834234182348128134The code does not compile.
36 What is the output of the following application?package office; import java.io.*; public class Printer { public void print() { try { throw new FileNotFoundException(); } catch (Exception | RuntimeException e) { System.out.print("Z"); } catch (Throwable f) { System.out.print("X"); } finally { System.out.print("Y"); } } public static void main(String… ink) { new Printer().print(); } }YXYZYThe code does not compile.The code compiles, but a stack trace is printed at runtime.None of the above.
37 What is the output of the following code?class ProblemException extends Exception { ProblemException(Exception e) { super(e); } } class MajorProblemException extends ProblemException { MajorProblemException(Exception e) { super(e); } } public class Unfortunate { public static void main(String[] args) throws Exception { try { System.out.print(1); throw new MajorProblemException( new IllegalStateException()); } catch (ProblemException | RuntimeException e) { System.out.print(2); try { throw new MajorProblemException(e); } finally { System.out.print(3); } } finally { System.out.print(4); } } }123123 followed by an exception stack trace12341234 followed by an exception stack traceDoes not compileNone of the above
38 What is the output of the following application?1: package robot; 2: public class Computer { 3: public void compute() throws Exception { 4: throw new NullPointerException("Does not compute!"); 5: } 6: public static void main(String[] b) throws Exception { 7: try { 8: new Computer().compute(); 9: } catch (RuntimeException e) { 10: System.out.print("zero"); 11: throw e; 12: } catch (Exception e) { 13: System.out.print("one"); 14: throw e; 15: } 16: } 17: }zeroonezero followed by a stack traceone followed by a stack traceDoes not compileNone of the above
39 Given the following class diagram, which two classes are missing in the hierarchy at positions 1 and 2?IOException at position 1, Exception at position 2Exception at position 1, RuntimeException at position 2IllegalArgumentException at position 1, RuntimeException at position 2IllegalStateException at position 1, RuntimeException at position 2Exception at position 1, FileNotFoundException at position 2None of the above
40 What is the output of the following application?package vortex; class TimeException extends Exception {} class TimeMachine implements AutoCloseable { int v; public TimeMachine(int v) {this.v = v;} public void close() throws Exception { System.out.print(v); } } public class TimeTraveler { public static void main(String[] twelve) { try (var timeSled = new TimeMachine(1); var delorean = new TimeMachine(2); var tardis = new TimeMachine(3)) { } catch (TimeException e) { System.out.print(4); } finally { System.out.print(5); } } }1235321551235321The code does not compile.None of the above.
41 Which of the following are common reasons to add a checked exception to a method signature? (Choose three.)To alert developers that the state of the JVM has been corruptedTo force a caller to handle or declare potential problemsTo ensure that exceptions never cause the application to terminateTo notify the caller of potential types of problemsTo give the caller a chance to recover from a problemTo annoy other developers
42 Which statement about the following application is correct?package highway; import java.io.*; class CarCrash extends RuntimeException { CarCrash(Exception e) {} // w1 } public class Car { public static void main(String[] s) throws Exception { // w2 try { throw new IOException("Auto-pilot error"); } catch (Exception | CarCrash e) { // w3 throw e; } catch (Exception a) { // w4 throw a; } } }The code does not compile because of line w1.The code does not compile because of line w2.The code does not compile because of line w3.The code does not compile because of line w4.The code compiles and prints a stack trace at runtime.None of the above.
43 Which of the following exception classes must be handled or declared in the method in which they are thrown? (Choose three.)public class Happy extends IOException {} public class Dopey extends Grumpy {} public class Sleepy extends IllegalStateException {} public class Sneezy extends UnsupportedOperationException {} public class Doc extends AssertionError {} public class Grumpy extends SQLException {}HappyDopeySleepySneezyDocGrumpy
44 What is the output of the following application?package pond; abstract class Duck { protected int count; public abstract int getDuckies(); } public class Ducklings extends Duck { private int age; public Ducklings(int age) { this.age = age; } public int getDuckies() { return this.age/count; } public static void main(String[] pondInfo) { Duck itQuacks = new Ducklings(5); System.out.print(itQuacks.getDuckies()); } }015The code does not compile.The code compiles but throws an exception at runtime.None of the above.
45 Which statements about the following line of code are correct? (Choose three.)throw new IllegalArgumentException ();The method where this is called must declare a compatible exception.The code where this is called can include a try‐with‐resources block that handles this exception.This exception should not be handled or declared.The code where this is called can include a try/catch block that handles this exception.This exception should be thrown only at the start of a method.This exception does not need to be handled by the method in which it is called.
46 What is the output of the following application?package storage; import java.io.*; public class