Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ocaexamcodingpractice;
- public class ExceptionsTestNumber9 {
- public void start() {
- try {
- System.out.print("Starting up");
- throw new Exception();
- } catch (Exception e) {
- System.out.println("Problem");
- System.exit(0);
- } finally {
- System.out.println("Shutting down");
- }
- }
- public static void main (String [] args) {
- new ExceptionsTestNumber9().start();
- }
- }
- /* What is the output of the following program?
- *
- * A. Starting up
- * B. Starting up Problem
- * C. Starting up Problem Shutting Down
- * D. Starting up Shutting Down
- * E. The code does not compile
- * F. An uncaught exception is thrown
- *
- * What is going on here? It is actually super easy!
- *
- * 1. The main method calls start() on a new ExceptionsTestNumber9
- * 2. Start() runs and Starting up is printed. Start() throws Exception e
- * 3. Code moves to catch block where Exception e is handled. Problem is then printed.
- * 4. System.exit() is called, which terminates the JVM, and nothing else is executed! DONE!
- *
- * So, the correct answer is B.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement